Im having difficulties parameterizing (data driven) checkboxes using Selenium IDE. When I record selecting a checkbox using Selenium i get the following action:
<tr>
<td>click</td>
<td>id=_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel</td>
<td></td>
In order to parameterize this action and pointing to my test data (XML) file I need a value which I can set as a variable. But in this action there is no value, only a target which is the ID.
Any ideas how to parameterize this action or how to check the checkbox using a value instead of using only the target (ID)?
P.S. Text fields work fine by putting "${Parametername}" in value field in Selenium for an action. The Parametername will then be my column name in my test data file.
Html code of the checkboxes:
<table class="detailgrid" cellspacing="0" border="0" id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels" style="border-style:None;border-collapse:collapse;">
<tbody><tr>
<td style="width:20px;">
<span disabled="disabled"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl2:chkbxChannel" checked="checked" disabled="disabled"></span>
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_lblChannelNaam">POS</span>
</td>
</tr><tr>
<td style="width:20px;">
<input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl3:chkbxChannel">
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_lblChannelNaam">eCommerce</span>
</td>
</tr><tr>
<td>
<br>
<span type="checkbox"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl4_chkalles1" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl4:chkalles1" onclick="CheckAll('chkbxChannel', this.checked);"></span>
</td><td>
<br>
Alles Aan
</td>
</tr>
</tbody></table>
Still use a click but change how you find the target by using xpath.
It would look something like this:
Target:
xpath=//td/span[text()='POS']
Hope this helps!
After going through the question, I tried using parameter for Target in the test step( as it was not possible to parameterize Action(Command) after various attempts) in Selenium IDE.
To select a checkbox the Xpath should point to the input tag and can be checked using click command.
IMO, as per the HTML, the correct Xpath for checking the checkbox corresponding to eCommerce should be :
//span[text()='eCommerce']/ancestor::td/preceding-sibling::td/input
Related
The below is a snippet from our html code which appears as a drop down list in the application. I am unable to select a particular value from the drop down list using Select class in Selenium - possibly because it doesn't have "Option" tags?. Is there any way to select the item?
-UPDATE: This has a parent tag which talks about visibility. Basically to tell that elements are visible only if the user clicks the drop down arrow.
"< input type="hidden" *****"
For e.g. I need to select 'I am option2' from the list during the test execution.
<div id="xyz" class="DropdownInnerContainer" style="z-index:99999;">
<table id="abc" class="DropdownItemContainer" list="1000020">
<tr class="">
<td value="" index="0" title="">
</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option1" index="1" plid="1002827">I am option1</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option2" index="2" plid="1002828">I am option2</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option3" index="3" plid="1002829">I am option3</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option4" index="4" plid="1002830">I am option4</td>
<td class="BorderCell"></td>
</tr>
</table>
If the text inside of the td that you want to select is unique, then you can click the table element with the id of 'abc' and then click the following element. The code provided is C#, but can be translated pretty easily.
IWebElement option = _driver.FindElement(By.XPath("//td[text()='I am option2']"));
It appears that since the drop down options were inside a < table >, the Select class was unable to identify the list options. So here's what I did:
First click() the dropdown, which opens up the menu:
driver.findElement(By.xpath(".//*[#id='abc01_tbl']/div/div")).click();
Then pass the value using the contains() method and then click() on it.
driver.findElement(By.xpath(".//*[#id='xyz01_tbl']/tbody/tr/td[1][contains(text(),'I am option2')]")).click();
You can not use Select in this scenario because there is no any select tag for dropdown. Drop down is under table body.
Please use below xpath for select option form drop down.
driver.findElement(By.xpath("//table[#id='abc']/tr[td[text()='your option text']]/td"));
I am trying to verify that a specific image exists on a webpage in a specific element. The image:
Has no unique id
Has no unique alt
The src attribute contains a query string I am trying to ignore
Appears multiple times on the page
I can't use Page Should Contain Image because it appears multiple times but I need to verify it appears in a specific table cell. The image src looks like this:
${BaseUrl}/status_submitted.png?master_2017217_17-29
Here's the HTML surrounding the image:
<table id="mass_list" class="grid">
<tr>
<th class="shrink align_center">Status</th>
<th>Action</th>
<th class="shrink align_right">Submitted</th>
<th class="shrink">Submitted By</th>
</tr>
<tr>
<td>
<img src="https://{baseurl}/images/status_submitted.png?master_2017217_17-29" alt="Submitted" width="70" height="20" />
</td>
<td class="nowrap">
Automation Test 1488321180.7
<br />
<small class="mute">
<strong>0</strong> of <strong>2</strong> records processed
</small>
</td>
<td class="nowrap align_right">Yesterday at 4:33 PM</td>
<td class="nowrap">Tina Tester</td>
</tr>
<tr>
<td>
<img src="https://{baseurl}/images/status_submitted.png?master_2017217_17-29" alt="Submitted" width="70" height="20" />
</td>
<td class="nowrap">
Add an attribute
<br />
<small class="mute">
<strong>0</strong> of <strong>16</strong> records processed
</small>
</td>
<td class="nowrap align_right">Yesterday at 8:06 AM</td>
<td class="nowrap">Tina Tester</td>
</tr>
I need to verify that just ${BaseUrl}/status_submitted.png exists on the page within a specific table cell or xpath location. How do I do this?
Given the example document this was a rather straight forward excersise for me using nothing more than Google Chrome itself. Put the contents of the example in a file with HTML/Body tags around it and then use the right-click inspect to inspect the element in the console. Right click again on the source tag and choose Copy>Xpath.
This will result in the following xPath: //*[#id="mass_list"]/tbody/tr[2]/td[1]/img where the first number tr[2]is the row, and the second number td[1] is the column.
A second approach is to look at the image tag itself and filter based on the file path location of the images with that src attribute: //img[contains(#src, "status_submitted.png")]
I been working on wizard . I been stuck in a tricky situation i.e
By default i am getting PREVIOUS , NEXT , FINISH . But i want to customize my wizard which having 4 stages .
on stage 1 & 2 : next & save button
stage 3 : send for approval
stage 4 : approve or reject
So for 4 stages i created 4 DIV's like this similarly
#using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<div id="step-1">
<h2 class="StepTitle">Step 1: Account Details</h2>
<table cellspacing="3" cellpadding="3" align="center">
<td align="center" colspan="3"> </td>
<tr>
<td align="right"> #Html.LabelFor(m=>m.Lead_Id) </td>
<td align="left">
: #Html.TextBoxFor(model=>model.Lead_Id , new { #readonly="readonly" } )
</td>
</tr>
<tr>
<td align="right"> #Html.LabelFor(m=>m.Contact_Name) </td>
<td align="left">
: #Html.TextBoxFor(model=>model.Contact_Name )
</td>
</tr>
<tr>
<td align="right"> #Html.LabelFor(m=>m.Contact_Address</td>
<td align="left">
: #Html.TextBoxFor(model => model.Contact_Address)
</td>
</tr>
<tr>
<td align="right"> #Html.LabelFor(m=>m.Lead_Source)</td>
<td align="left">
: #Html.DropDownListFor(c=>c.Lead_Source, Model.lead_sources)
</td>
</tr>
<tr>
<td> <input type="submit" value="SAVE" id="btnsave" /></td> // on click it does postback call to controller which saves my data accordingly . fine with that
<td><input type="button" onclick="donno()" value="NEXT STAGE" id="btnNext"</td> // Issue is here and what i need is onclick of button need to move to second stage of wizard so i been thinking to write a logic on click method of button ?
</tr>
</table>
</div>
}
I donno HOW ? Is it possible to call the next stage i.e next DIV of stage-2 to show up on-click.
Is there is any work around to bind DIV to the button . so on click of button that section of DIV should load in step2 of wizard .
Any better ideas are welcome and efforts are always appreciated .
Thanks & Regards
If you are trying to go through the steps of your wizard, you need some mechanism to do this. You have two options:
Use a jQuery wizard to handle everything client-side (you are talking about your <div>, so jQuery could "step" through each one"). Check this link out for a popular example: jQuery Wizard.
Although in the above you would use an MVC controller (or two if you use a partial view to display the "confirmation" or "submitted" page), another way to do this is using multiple controllers, one for each step, and then using TempData to keep user input data through the steps until you get to the end. Check this link out for an example: TempData Wizard.
You might get heated opinions about the use of TempData. I used the jQuery example before, but found it to be too cumbersome. I went the TempData route for simplicity (I hate LONG view or code pages, they tend to be hard to maintain).
Your mileage may vary, and ultimately it is up to you to decide what works best in your situation. Good luck.
Edit
Just also found a new (MVC5) link for using Session: Session Wizard. TempData is a form of Session, however, TempData is used for redirects in controllers, and unless you specifically "Keep" the TempData it is destroyed after the redirect. Both are not very secure, so just be aware of that (I believe in a secure application you can certainly use authentication (user or role based).
I have quite specific problem regarding both selenium and xpath.
I have to make an automated tests based on scenarios using selenium. All pages are automatically generated and using Ids is impossible.
All form elements though are designed in same way.
<table>
<tr><td> Title </td></tr>
<tr><td> input/dropdown/etc </td></tr>
</table>
He is the specifics
<tr>
<td width="34%" valign="top" bgcolor="#ffffc7">
<span class="bold">Status wniosku</span>
<span>Test</span>
</td>
<td width="66%" bgcolor="#ffffc7">
<select id="ctl00_ContentPlaceHolder_2041" class="baseCtrl" name="ctl00$ContentPlaceHolder$2041">
<option value="" selected="selected">- wybierz -</option>
<option value="save">tylko zapisz</option>
<option value="pj">zapisz i wyślij do PJ</option>
</select>
<span>
</span>
<span id="ctl00_ContentPlaceHolder_ctl19" class="validation" style="display:none;">Określ status wniosku</span>
<span id="ctl00_ContentPlaceHolder_ctl20" class="validation" style="display:none;"></span>
<span></span>
</td>
</tr>
Using http://www.xmlme.com/XpathTool.aspx I have designed xpath for dropdown elements.
//span[text()='LABELNAME']/ancestor::*[1]/following-sibling::*/select/option[text()='TEXTVALUE']
I would like to use Selenium to click on the element i found.
I've tried Selenium.Click() and variations of Selenium.Select() but with no results.
My question is, is the xpath designed correctly? If so how should i execute it using Selenium? Thx for the help.
Try below xpath for selecting second option
"//span[text()='Test']/ancestor::*[1]/following-sibling::*/select"
Ex:
Selenium.Select("//span[text()='Test']/ancestor::*[1]/following-sibling::*/select","label=Save");
i faced a problem while replaying a script created for yahoomail page.The XPath statement to enter value in the "To" text field , is not working.Following are the XPath statements i used.
At the first try i used
<tr>
<td>type</td>
<td>to</td>
<td>mgtest#ymail.com</td>
</tr>
Second try was this statement
<tr>
<td>type</td>
<td>//div[#id= 'toid']/textarea[#id= 'to'][#name= 'to']</td>
<td>mgtest#ymail.com</td>
</tr>
Third try was this
<tr>
<td>typeKeysAndWait</td>
<td>//div[# id= 'composebox']/div[#id= 'toid']/textarea[#id= 'to'][#name= 'to']</td>
<td>mgtest#ymail.com</td>
</tr>
The result was like
[error] Element //div[# id= 'composebox']/div[#id= 'toid']/textarea[#id= 'to'][#name= 'to'] not found
similar result was obtained in the previous attempts.
Later when i tried
<tr>
<td>type</td>
<td>css=textarea.txtfield</td>
<td>mgtest#ymail.com</td>
</tr>
mail id was entered into the text field ,and the script worked perfectly.what might be the reason.Any thoughts.?
I am adding the XPath statements
<div id="composepage">
<div id="composebox" class="roundcorner">
<div id="errorContainer"/>
<input type="hidden" name="defFromAddress" value="mgtest#ymail.com"/>
<div class="fields row">
</div>
<div id="toid" class="row">
<label id="compose_to" for="to">
</label>
<textarea id="to" class="txtfield" name="to" autocomplete="off" tabindex="1" style="overflow: hidden; height: 19px;"/>
</div>
You have written invalid xpath query.
It should be
//div[# id='composebox']/div[#id='toid']/textarea[#id='to' and #name='to']
The <textarea> has an id attribute, which should be unique, so your first locator of simply to should work. It's possible that the element is not present or visible when your selenium command executes. I would recommend the following:
waitForVisible | id=to | 60000
type | id=to | mgtest#ymail.com
If your elements have unique ids, and you need to use XPath, you only need to be relative to the closest element with an id attribute.