簡體   English   中英

如何使用js和selenium檢查Select Web元素是否包含某些文本?

[英]How to check if a Select web element contains certain text using js and selenium?

我是一個隱藏的下拉式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')") 

現在,這很完美,但是現在我想通過可見文本選擇元素...

所以我嘗試做類似的事情:

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')")

但它不起作用...有人知道為什么它起作用了嗎?還是有更好的解決方案? 我在Scala中編程,但是Java解決方案也可以。

謝謝!

jQuery contains選擇器應寫為#company_id option:contains("Test")

所以:

$('#company_id option:contains("Test")').eq(1)...

Codepen: http ://codepen.io/anon/pen/dGqXzG

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM