2014-11-03 52 views
1

我的例子是:RSelenium單選按鈕點擊似乎並不奏效

library(RSelenium) 
remDr <- remoteDriver() 
remDr$open(silent = TRUE) 
remDr$navigate("http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/") 
remDr$findElement("id", "three")$click() 

似乎這不工作。有人可以幫助解決問題嗎?

回答

0

您正處在正確的軌道上。綜觀?remoteDriverclick方法描述爲:

click(buttonId = 0) Click any mouse button (at the coordinates set by the last mouseMoveToLocation() command). buttonId - any one of 'LEFT'/0 'MIDDLE'/1 'RIGHT'/2. Defaults to 'LEFT'

此方法是點擊屏幕上的位置。您的代碼可以稍微更改,以便分配findElement方法結果。

library(RSelenium) 
# startServer() # start Selenium Server if needed 
remDr <- remoteDriver() 
remDr$open(silent = TRUE) 
remDr$navigate("http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/") 
webElem <- remDr$findElement("id", "three") 

> class(webElem) 
[1] "webElement" 
attr(,"package") 
[1] "RSelenium" 

看着爲webElement類的文檔有一個方法clickElement

webElem$clickElement() 

使用這種方法應該產生所需要的結果。

+0

非常感謝!這工作。 – kennyB 2014-11-04 03:47:02

+0

樂意幫忙... – jdharrison 2014-11-04 03:49:03