RSelenium和Javascript

RSelenium和Javascript,第1张

RSelenium和Javascript

您不需要在

executescript
这里使用:

require(RSelenium)checkForServer()startServer()remDr<-remoteDriver()remDr$open()remDr$getStatus()remDr$navigate("http://fyed.elections.on.ca/fyed/en/form_page_en.jsp")p.pres<-c('m1p4v4', 'n3t2y3', 'n2h3v1')webElem<-remDr$findElement(using = 'id', value = "ppre")webElem$sendKeysToElement(list(p.pres[1])) # send the first post pre to the elementremDr$findElement("id", "en_btn_arrow")$clickElement() # find the submit button and click it

如果您想使用它,

executescript
则可以将最后一行替换为:

remDr$executescript("arguments[0].click();"     , list(remDr$findElement("id", "en_btn_arrow")))

executescript
脚本作为参数和列表。如果列表中的任何元素属于类,
webElement
则可以像DOM元素一样在脚本中引用它们。在这种情况下,第一个元素(Javascript中的零索引)是a
webElement
,我们要求在Javascript中单击它。

此外,如果您检查按钮后面的源代码,就会发现在按下按钮时它会

document.ppre.submit()
更简单地调用(在这种情况下,如果您想使用),
executescript
您可以执行以下 *** 作:

remDr$executescript("document.ppre.submit();")


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4988470.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存