使用 RSelenium 单击下拉列表 window 中的值
Click on value in dropdown window using RSelenium
在以下网站上:https://www.bhtelecom.ba/index.php?id=7226&a=new
我想在您单击 "Sarajevo (033)" 后应用的下拉列表 window ("Tuzlanski (035)") 中选择第二个值。我想使用 RSelenium 来做到这一点。
我尝试了在 Whosebug 上找到的 10 种不同的解决方案,但没有一个有效。我认为是因为它是由 javascript.
生成的
我尝试过的解决方案之一:
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L,
browserName = "chrome")
remDr$open()
remDr$navigate("https://www.bhtelecom.ba/index.php?id=7226&a=new")
option <- remDr$findElement(using = 'xpath', "//select[@id='di']/option[@value='035']")
option$clickElement()
首先你必须点击输入字段:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
然后选项将可见,您可以 select 使用右 xPath
:
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
您可能需要使用这个:
Sys.sleep(5) # wait 5 seconds
如果脚本太快,将尝试 select 在下拉列表出现之前下拉元素。
摘要代码:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
Sys.sleep(5) # wait 5 seconds
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
你也错了xPath
:
在以下网站上:https://www.bhtelecom.ba/index.php?id=7226&a=new 我想在您单击 "Sarajevo (033)" 后应用的下拉列表 window ("Tuzlanski (035)") 中选择第二个值。我想使用 RSelenium 来做到这一点。
我尝试了在 Whosebug 上找到的 10 种不同的解决方案,但没有一个有效。我认为是因为它是由 javascript.
生成的我尝试过的解决方案之一:
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L,
browserName = "chrome")
remDr$open()
remDr$navigate("https://www.bhtelecom.ba/index.php?id=7226&a=new")
option <- remDr$findElement(using = 'xpath', "//select[@id='di']/option[@value='035']")
option$clickElement()
首先你必须点击输入字段:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
然后选项将可见,您可以 select 使用右 xPath
:
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
您可能需要使用这个:
Sys.sleep(5) # wait 5 seconds
如果脚本太快,将尝试 select 在下拉列表出现之前下拉元素。
摘要代码:
input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
input$clickElement()
Sys.sleep(5) # wait 5 seconds
option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
option$clickElement()
你也错了xPath
: