将按键发送到元素

时间:2015-12-16 08:30:22

标签: r selenium

我尝试从here

运行示例

在使用firebug for google write box的firefox中我可以看到这个以找到id:

<input id="gs_htif0" class="gsfi" disabled="" autocomplete="off" aria-hidden="true" style="border: medium none; padding: 0px; margin: 0px; height: auto; width: 100%; position: absolute; z-index: 1; background-color: transparent; color: silver; transition: all 0.218s ease 0s; opacity: 0; text-align: left; left: 0px;" dir="ltr">

使用以下代码:

library("RSelenium")
startServer()
checkForServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate("https://www.google.com/")
webElem <- remDr$findElement(using = "xpath", "//*/input[@id = 'gs_htif0']")
webElem$sendKeysToElement(list("R Cran", "\uE007"))

我收到的错误如下:

Error:   Summary: InvalidElementState
     Detail: An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
     class: org.openqa.selenium.InvalidElementStateException

1 个答案:

答案 0 :(得分:2)

您似乎使用了不正确的xpath,Google搜索框的正确xpath为//*[@id="lst-ib"]

希望它能解决您的问题。