如何从硒中的嵌套XPath获得价值
我正在尝试使用Selenium和Java测试一个我想要实现的应用程序。
单击一个选择框(有效的框),然后从多个selectoption中选择一个等于我的输入的框。因此,如果我的功能文件说狗,我希望从“选项狗”中选择狗。
打开选择后选择选项的代码看起来像这样:
WebElement xyz = driver.findElement(By.xpath(String.format("//*[@id='xyz']/div[2]/ul/li[text()='%s']",selectElement)));
如果我删除 /li,则在浏览器中的控制台中选择每个选项,所以我想使用/li [text()='%s'] < /代码>我可以动态设置选项名称。但是我得到了鼻nocelementExcetion,我的错误可能是什么?如果我正确1而不是
text()='%s'
我可以选择选项
I am trying to test an application with Selenium and Java, what I want to achieve, is the following.
Click on a select box (which works) and then select from a multiple selectoption the one equaling my input. So if my Feature file says dog I want from the options dog to be selected.
My code to select the option after opening the selectbox looks like this:
WebElement xyz = driver.findElement(By.xpath(String.format("//*[@id='xyz']/div[2]/ul/li[text()='%s']",selectElement)));
If I delete /li every option is selected in my console in the browser, so I thought with /li[text()='%s']
I could dynamically set the option name. But I am getting a nosuchelementexcetion, what could be my mistake? If i right 1 instead of text() = '%s'
I am being able to select the option
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于选择框,您需要创建一个针对选择框的
选择
对象,然后按值选择要选择要选择的项目。例如:希望这会有所帮助:)
For the select box, you need to create a
Select
object which targets the select box and then select by value to get the item you want to select. For example:Hope this helps :)