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");
Related
Below is the html markup and I want to extract mobile number 7788996655 using xpath:-
<table class="table hover" id="resultTable">
<tbody>
<tr class="odd">
<td class="left">
<img src="/symfony/web/index.php/pim/viewPhoto/gamerNumber/1/from/gameDir" height="200" width="196">
</td>
<td class="left">
<span style="font-weight:bold;">John Player</span>
<br>
<span style="font-weight:bold;">Email: </span>
john.player#yyeett.com,
<span style="font-weight:bold;">
Mobile: </span>7788996655,
<span style="font-weight:bold;">Skype: </span>
game.player,
<br>
<span style="font-weight:bold;">Designation: </span>
Moderator,
<br>
<span style="font-weight:bold;">Game Name: </span>
Counter Strike
<br>
</td>
</tr>
</tbody>
</table>
I tried below xpath, but it didn't worked:
//td/span[contains(.,'Mobile:')]/following-sibling::text()[1]
Can someone provide solution for this?
Workaround I tried is to get whole text within td and then used pattern matching regex to extract mobile number from it. But, now i want to know whether is it possible using xpath?
You can do it using below XPath
<parent td node xpath>/text()[preceding-sibling::span[1][text() = 'Mobile: ']]
Now for an explanation. /td/text() will select each text which is part of the td node but is not part of any other node. So in this case it ,,7788996655,, game.player, moderator.
Now out of these 4 text we want to filter out one which has a previous sibling, which is a span and has text Mobile:, so we can add [preceding-sibling::span[1][text()='Mobile: ']]
<tr>
<td>
<span class="dijitArrowNodeInner" data-dojo-attach-point="arrowNodeInner"/>
</td>
<td>
<div class="dijitTitlePaneTextNode" data-dojo-attach-point="titleNode" style="-moz-user-select: none;">
<div>Scripts</div>
</div>
</td>
</tr>
What will be the xpath for the above expression to get the 'Script'.
If by "the Script" you mean the text content of the inner div element:
/tr/td/div/div
Else, if you mean the div element that has "Scripts" as its content:
//div[. = 'Scripts']
But I doubt this is of much help unless you explain exactly what you need.
From your sample provided, this should work:
//tr/td/div[#class='dijitTitlePaneTextNode']/div[text()]
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
<div class="row">
<div class="row">
<table>
<tbody>
<tr>
<td class="list-text">
<div style="background-color: transparent;">Testing this function</div>
</td>
<td class="list-buttons" rowspan="2">
Config
<a class="edit-button" href="javascript:;">Edit</a>
<a class="save-button" href="javascript:;" style="display:none;">Save</a>
Delete
</td>
</tr>
<tr>
</tbody>
</table>
</div>
I need to find the element which contains the text "Testing this function" and click to link "Config".
Can't find a way to do it.
Edited: Found a way to do it:
By.xpath("//div[#class='row']/table/tbody/tr[td/div[contains(.,'Testing')]]/td[2]/a[contains(.,'Config')]")
But maybe someone has a better solution for this?
If you have to use text, my preference would be;
By.xpath("//div[contains(text(),'Testing')]]//a[contains(text(),'Config')]") .
I prefer using "text()" to "." just for readability. Apologies if "." is actually a better approach which I wasn't aware of.
Also unless you have a specific reason, I would avoid using tightly coupled xpath. E.g. I have not used " td[2]", instead I have said the"a" can be anywhere within in the "div"
Below is my code.
This is my combobox/dropdown box
<TR id="oldcontent" bgcolor="#D0D0D0">
<TD ALIGN="left" id="oldcontent">
<select name="status" style="width=150" id="newcontentformat">
<option value="15">Approved1</option>
<option value="16">Approved2</option>
<option value="17">Approved3</option>
</TD>
</TR>
how do i select the value Approved2?can anyone help me with the xpath?
I tried the below..but its not working
selenium.select("//select[#name='status']",Approved2);
selenium.select("status",Approved2);
Also i have multiple and and i need to select the combobox present in very first .
Thanks in Advance for help
The second parameter of the method has to be a string. Try:
selenium.select("//select[#name='status']", "Approved2");