【发布时间】:2016-11-30 15:11:31
【问题描述】:
我使用 RSelenium 填写网络表单。要从下拉列表中选择一个选项,我使用以下命令:
xpathoption <- paste0("//select[@id = '",samplepatient[p,'name'],"']/option[",samplepatient[p,'value'],"]")
optionelem <- remDrv$findElement(using = "xpath", xpathoption)
selectelem <- remDrv$findElement(using = "xpath"
, paste0("//select[@id = '",samplepatient[p,'name'],"']"))
optionelem$clickElement()
selectelem$screenshot(display = T)
我使用以下方法检查是否选择了正确的选项:
remDrv$findElement(using = "xpath", paste0("//select[@id = '",samplepatient[p,'name'],"']"))$getElementAttribute("value")[[1]]
我遇到的问题是当clickElement() 命令运行两次时,最后一个命令的结果发生了变化。我还用screenshot() 检查了结果。它还表明,当使用两次clickElement() 命令时,切换到了不同的选项。
是否有其他方法可以从下拉列表中选择选项,而不是创建此行为?
我在 ubuntu 上使用 docker 和 firefox 3.0.1。
表格来自我想使用的计算器。要打开表单本身,您需要先检查免责声明,如下所示:
remDrv$navigate('http://riskcalculator.facs.org/RiskCalculator/')
remDrv$findElement(using = "xpath", "//input[@id = 'chkDisclaimer']")$clickElement()
Sys.sleep(1)
remDrv$findElement(using = "xpath", "//input[@id = 'btnContinue']")$clickElement()
Sys.sleep(1)
免责声明后的可重现示例是:
#select age group
optionelem <- remDrv$findElement(using = "xpath", "//select[@id = 'AgeGroup']/option[3]")
selectelem <- remDrv$findElement(using = "xpath", "//select[@id = 'AgeGroup']")
#first attempt
optionelem$clickElement()
selectelem$getElementAttribute("value")
# result = 3
#second attempt
optionelem$clickElement()
selectelem$getElementAttribute("value")
# result = 1
【问题讨论】:
-
是否可以提供您填写表格的网页?
-
我在问题中添加了网页信息
-
我已经查看了这个运行最新的 chrome,但我没有看到这个问题(即结果在两种情况下都返回为 3)。我将很快运行 Docker 镜像 Standalone-firefox-debug:3.0.1-barium 并查看问题是否存在。
-
我可以重现这个正在运行的
docker run -d -p 5901:5900 -p 127.0.0.1:4444:4444 selenium/standalone-firefox-debug:3.0.1-barium。这可能是 geckodriver github.com/mozilla/geckodriver/issues/322 的问题 -
正在运行
docker run -d -p 5901:5900 -p 127.0.0.1:4444:4444 selenium/standalone-chrome-debug:3.0.1-barium我没有遇到这个问题。如果 chrome 对您有用,那么可以使用此图像。否则,您可以尝试使用旧版本的 Firefox 映像,请参阅 hub.docker.com/r/selenium/standalone-firefox-debug/tags 。