【问题标题】:Click on value in dropdown window using RSelenium使用 RSelenium 在下拉窗口中单击值
【发布时间】:2018-06-16 08:59:43
【问题描述】:

在以下网站上:https://www.bhtelecom.ba/index.php?id=7226&a=new 我想在单击“Sarajevo (033)”后出现的下拉窗口(“Tuzlanski (035)”)中选择第二个值。我想使用 RSelenium 来做到这一点。

我尝试了在 stackoverflow 上找到的 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()

【问题讨论】:

    标签: r rselenium


    【解决方案1】:

    首先你必须点击输入字段:

    input <- remDr$findElement(using = 'xpath', "//input[@class = 'select-dropdown']")
    input$clickElement()
    

    然后选项将可见,您可以使用正确的xPath 选择它们:

    option <- remDr$findElement(using = 'xpath', "//span[contains(., 'Tuzlanski (035)')]")
    option$clickElement()
    

    您可能需要使用这个:

    Sys.sleep(5) # wait 5 seconds
    

    如果脚本太快并且会在下拉菜单出现之前尝试选择下拉元素。

    摘要代码:

    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

    【讨论】:

    • 我不适合我:它给我一个错误 Error: Summary: ElementNotVisible fo 最后一个命令 (option$clickelement())
    • input$clickElement()之后添加Sys.sleep(5)
    • 没用
    • 我找到了问题,有错误xPath,请看答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多