jgl*_*lgb 6 firefox r rselenium
我正在尝试使用 Firefox 学习 R 中的 RSelenium。我已经可以找到所需的元素并将鼠标移到它上面,但是当我尝试右键单击它时,它最终会被左键单击。
我尝试阅读文档(?remoteDriver并且?webElement确实很有帮助),但是webElement类只有clickElement方法,默认情况下左键单击并且没有参数,并且remoteDriver有click带参数的方法buttonId,其中 2 或“RIGHT”应该是鼠标右键单击当前已找到,但由于某种原因,它无法按我的预期工作,而是执行左键单击。
请注意,我知道 JavaScript、Selenium、使用 PhantomJS 等中存在关于相同问题的问题,我已经阅读过它们,但它们对我没有帮助。如果您觉得我错过了一些东西,请随时给我一个链接。
我的目标也不是仅仅在新选项卡中打开页面,这只是可以通过右键单击元素来执行的操作的示例。
我能想到的最小的可重现示例是:
library(RSelenium)
rd <- rsDriver(browser = 'firefox')
rdc <- rd$client
rdc$navigate('http://google.com/ncr')
elem <- rdc$findElement('partial link','About')
rdc$mouseMoveToLocation(webElement = elem)
# the following should open contextual menu, but enters the "About" page instead
rdc$click(buttonId = 'RIGHT')
# if the above line worked correctly, the following should open the "About" page in new tab
# rdc$sendKeysToActiveElement(list(key='down_arrow',key='enter'))
# rd$server$stop() # close everything and free the port
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
您可能会想知道,但您应该在脚本中进行的唯一更改如下:
rdc$click(buttonId = 2)
Run Code Online (Sandbox Code Playgroud)
它将触发 element 中间的右键单击。