cannot get form element using selenium - selenium

<h6>
top
<form method="post" name="prod" action="blah.jsp>
<input type="hidden" name="a" value="asdfsd">Jump to product:
<input type="text" name="p" size="25">
GO
</form>
<form method="get" name="catgy" action="cato.jsp">
<input type="hidden" name="a" value="asdfs3">Jump to category:
<input type="text" name="c" size="25">
GO
</form>
</h6>
Neither this returns element
WebElement form = driver.findElement(By.xpath("//body/h6/form[2]"));
nor
WebElement form = driver.findElement(By.name("catgy"));
Can you please help get the form element?

Try this
driver.findElement(By.cssSelector("form[name='catgy']"));

Related

Asp .net MVC 4.0 | how can I post a HTML form using URL.Action to a secure page?

I have a HTML form on a page which is not running on the secure binding but I need to post this form to a secure page. Now issue I am facing is that my form data gets lost when I submit this form.
I am using following following code for the form:
<form id="pdp-form" action="#Url.Action("action", "Controller")" method="post">
<input type="hidden" value="" name="Size" id="pdp-size">
<input type="hidden" value="" name="ProductId" id="pdp-code">
<input type="hidden" name="Product" id="pdp-ProductName" value="Product Name">
<input type="hidden" name="Category" id="pdp-Category" value="Category Name">
<input type="hidden" value="buyID" name="ProdBuyId" id="ProdBuyId">
</form>
How can I post my from on the secure page without loosing my data?
Note : Secure page where we are posting the form has both get and post methods.
i don't know what are you trying to do, but you're missing the submit button
<button type="submit">Submit</button>
<form role="form" action="#Url.Action("action", "Controller")" method="post">
<input type="hidden" value="" name="Size" id="pdp-size">
<input type="hidden" value="" name="ProductId" id="pdp-code">
<input type="hidden" name="Product" id="pdp-ProductName" value="Product Name">
<input type="hidden" name="Category" id="pdp-Category" value="Category Name">
<input type="hidden" value="buyID" name="ProdBuyId" id="ProdBuyId">
<button type="submit">Submit</button>
</form>

using Bootstrap3 form in laravel5.1

I am trying to make a form using bootstrap3 in laravel5.1 so that I can get values from user and store it on the database and want to redirect the same page.
here is the form part of my code --
<div class="row">
<form action="{{url('fastshops/menu')}} " method="post" role="form">
<legend>ADD NEW ITEM</legend>
<div class="form-group">
<label for=""></label>
<input type="text" class="form-control" name="ItemID" id="" placeholder="Item ID...">
<label for=""></label>
<input type="text" class="form-control" name="ItemName" id="" placeholder="Item Name...">
<label for=""></label>
<input type="text" class="form-control" name="SellPrice" id="" placeholder="Sell Price...">
<label for=""></label>
<input type="text" class="form-control" name="NetPrice" id="" placeholder="Net Price...">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
but this part action="{{url('fastshops/menu')}} is not working ! If I click on the submit button I am having TokenMismatchException ! please help me out.
thanks in advance.
add this
<input type="hidden" name="_token" value="{{Session::token()}}"/> or
<input type="hidden" name="_token" value="{{csrf_token()}}"/>
inside your form.
Laravel 5 automatically check for CSRF on all Post request for all the routes. Read the docs, they are pretty self explainatory

Click on multiple checkboxes at the same time with selenese (selenium)

Given the html below, I want to click, with a selenese (selenium xml), all cheboxes which name attribute is "y".
With or whitout (if possible) flow control js.
Code example:
<html>
<body>
<form action="">
<input type="checkbox" name="x" value="v1">v1<br>
<input type="checkbox" name="x" value="v2">V2<br>
<input type="checkbox" name="x" value="v3">v3<br>
<input type="checkbox" name="y" value="v4">v4<br>
<input type="checkbox" name="y" value="v5">v5<br>
<input type="checkbox" name="y" value="v6">v6<br>
<input type="checkbox" name="z" value="v7">v7<br>
<input type="checkbox" name="z" value="v8">v8<br>
<input type="checkbox" name="z" value="v9">v9<br>
</form>
</body>
</html>
Thank you!

Symfony 2 - Contact form and validation

I'm having trouble with contact form on Symfony 2.
Simple form
<form id="contact-form" method="post" action="">
<label for="name">Name: </label>
<input type="text" name="name" id="name" class="input" />
<label for="subject">Subject: </label>
<input type="text" name="subject" id="subject" class="input" />
<label for="text">Text: </label>
<textarea name="text" id="text" class="input"></textarea>
</form>
I read the documentation about validations and form, but I didn't really understand what it was about.
I have two questions
where should post values go, I'm talking about action attribute in form.
how can I validate this simple contact form.
The best would be if you guys show me here or link to how to validate this simple form.
Thanks
You can set the action to any path in your routing. Example <form action="{{ path(...) }}">. From the path, there will be redirect to your controller. In your controller, you can validate the form. I will give you example.
<form id="contact-form" method="post" action="{{ path('form_contact') }}">
<label for="name">Name: </label>
<input type="text" name="name" id="name" class="input" />
<label for="subject">Subject: </label>
<input type="text" name="subject" id="subject" class="input" />
<label for="text">Text: </label>
<textarea name="text" id="text" class="input"></textarea>
</form>
From here, this form will go through routing
// in your routing.yml
form_contact:
pattern: contact
defaults:
_controller: YourNewBundle:Test:contact
Now, let's go to controller part
// TestController.php
public function contact(){
$request = $this->getRequest();
if ($request->query->has('name') || $request->query->has('subject') || $request->query->has('text')){
...
}
}
Just customize with your own code.

Dojo Form upload does not show text box

<input name="uploadedFile" type="file" id="uploader"
data-dojo-type="dojox/form/Uploader"
data-dojo-props="style:'height: 26px; width: 75px; '" label="Browse" />
The above code show only label and Browse button only, not text box. How to show label textbox and browse button respectively.
See the tests here: http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1/dojox/form/tests/test_Uploader.html
Specify the showInput:'before' option in your data-dojo-props.
<form method="post" action="UploadFile.php" id="myForm2" enctype="multipart/form-data" >
<fieldset>
<legend>Inline Browse Button Form Post Test</legend>
<div data-dojo-type="dojox.form.Uploader" id="uploader2" data-dojo-props="name:'uploadedfile',showInput:'before',isDebug:true">Browse</div>
<input type="text" name="album" value="Summer Vacation" />
<input type="text" name="year" value="2011" />
<input type="button" id="remBtn2" label="Clear" dojoType="dijit.form.Button" />
<input type="submit" label="Submit" dojoType="dijit.form.Button" />
<div id="files2" dojoType="dojox.form.uploader.FileList" uploaderId="uploader2"></div>
</fieldset>
</form>