[英]How to check if a Select web element contains certain text using js and selenium?
I a hidden dropdown web element that currently im un-hidding and selecting by value like this: 我是一个隐藏的下拉式Web元素,该元素当前未隐藏并按如下所示通过值进行选择:
val js: JavascriptExecutor = driver.asInstanceOf[JavascriptExecutor]
js.executeScript("$('.select-upload_company_id>.center').html(" + someInt + ")") //visible one
js.executeScript("$('#company_id option[value=\"" + someInt + "\"]').eq(1).attr('selected','selected')")
Now, this works perfectly, but now I want to select the element by visible text... 现在,这很完美,但是现在我想通过可见文本选择元素...
So I tried to do something like: 所以我尝试做类似的事情:
val js: JavascriptExecutor = driver.asInstanceOf[JavascriptExecutor]
js.executeScript("$('.select-upload_company_id>.center').html(" + "Test" + ")") //visible one
js.executeScript("$('#company_id option[contains=\"" + "Test" + "\"]').eq(1).attr('selected','selected')")
but its not working...does someone either know why it dosent work or have a bettes and simpler solution? 但它不起作用...有人知道为什么它起作用了吗?还是有更好的解决方案? I'm programming in scala but java solutions will be fine too.
我在Scala中编程,但是Java解决方案也可以。
thanks! 谢谢!
The jQuery contains
selector should be written like #company_id option:contains("Test")
jQuery
contains
选择器应写为#company_id option:contains("Test")
So: 所以:
$('#company_id option:contains("Test")').eq(1)...
Codepen: http://codepen.io/anon/pen/dGqXzG Codepen: http ://codepen.io/anon/pen/dGqXzG
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.