2016-10-16 30 views
2
findElement功能

我試圖運行此代碼:錯誤在RSelenium

library(RSelenium) 

pJS<- phantom() 

remDr <- remoteDriver(browserName = "phantomjs") 

url<- "http://www.magicbricks.com/property-for-rent/residential-real-estate?proptype=Multistorey-Apartment,Builder-Floor-Apartment,Penthouse,Studio-Apartment,Service-Apartment,Residential-House,Villa&cityName=Mumbai" 

remDr$open() 

remDr$navigate(url) 

webElem1 <- remDr$findElement("name", ">5 BHK") 

webElem2 <- remDr$findElement("css", "#refinebedrooms li:nth-child(6)") 

webElem3 <- remDr$findElement("css", "#viewMoreButton a") 

但我不斷收到以下錯誤:

Error: Summary: NoSuchElement Detail: An element could not be located on the page using the given search parameters. class: org.openqa.selenium.NoSuchElementException Further Details: run errorDetails method

這是什麼意思?我該如何克服它?我是新來的R和RSelenium的第一次使用者,所以任何形式的幫助將不勝感激? TIA

回答

1

首先,如果您是新手,我強烈建議您閱讀幫助文件R-SELENIUM,然後嘗試使用該軟件包。

名稱> 5 BHK的元素不存在。這就是你遇到錯誤的原因。但是webElem2和webElem1是一樣的(如果這有效的話)。

所以要回答你的問題,你必須確定發生錯誤的位置。而且錯誤很明顯。 NoSuchElement

因此,您的三個webelements1,2,3中的一個在webdriver的頁面中沒有看到。如果您想使用css來識別元素,假設您也是HTML新手,那麼我建議您使用Selector gadget來識別使用的元素cssxpath