RSelenium中的finelement函数出错



我正在尝试运行这段代码:

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")

但是我一直得到以下错误:

错误:Summary: NoSuchElement详细信息:使用给定的搜索参数无法在页面上找到元素。类:org.openqa.selenium.NoSuchElementException详细信息:运行errorDetails方法

这是什么意思?我怎样才能克服它?我是R的新手和RSelenium的第一次用户,所以任何类型的帮助将非常感激?TIA

首先,如果您是新手,我强烈建议您浏览一下帮助文件R-SELENIUM,然后尝试使用该包。

名称> 5bhk的元素不存在。这就是你得到错误的原因。但webElem2是相同的webElem1(如果这工作)。

所以要回答你的问题,你必须找出错误发生的地方。这个错误是不言而喻的。NoSuchElement

所以你的三个webement1,2,3中的一个在网页驱动程序中没有看到。如果您想使用css识别元素,假设您也是HTML新手,我建议您使用选择器小工具使用cssxpath

来识别元素。

最新更新