[英]Selenium select dropdown element using xpath string
I have quite specific problem regarding both selenium and xpath. 关于硒和xpath,我有一个非常具体的问题。
I have to make an automated tests based on scenarios using selenium. 我必须根据使用硒的场景进行自动化测试。 All pages are automatically generated and using Ids is impossible. 所有页面都是自动生成的,因此无法使用ID。
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. 使用http://www.xmlme.com/XpathTool.aspx,我为下拉列表元素设计了xpath。
//span[text()='LABELNAME']/ancestor::*[1]/following-sibling::*/select/option[text()='TEXTVALUE']
I would like to use Selenium to click on the element i found. 我想使用Selenium单击找到的元素。 I've tried Selenium.Click() and variations of Selenium.Select() but with no results. 我已经尝试过Selenium.Click()和Selenium.Select()的变体,但是没有结果。
My question is, is the xpath designed correctly? 我的问题是,xpath设计正确吗? If so how should i execute it using Selenium? 如果是这样,我应该如何使用Selenium执行它? Thx for the help. 谢谢。
Try below xpath for selecting second option 尝试在xpath下选择第二个选项
"//span[text()='Test']/ancestor::*[1]/following-sibling::*/select"
Ex: 例如:
Selenium.Select("//span[text()='Test']/ancestor::*[1]/following-sibling::*/select","label=Save");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.