此页面的主菜单(linio)有11个链接。只对9(灰色背景和徘徊时显示子菜单)感兴趣。RSelenium:单击不可见对象 - ElementNotVisibleException
我想单击9个选项中的子菜单中的每个单个元素。期望的方法是:
1.-第一部分:“Celulares y Tablets”。
2. - 转到:“Celulares y智能手机”。请点击并看到此页面。
3.提取一些数据(检查,我已经能够做到这一点)。
4.转到“Celulares y Tablets”中的下一个子菜单。这是:“Accesorios Celular”。
5.提取一些数据,然后进入下一个子菜单。在完成了本节中的所有子菜单后,我将转到下一个大节:“TV-Audio-y-Foto”。
等9个部分。
HTML Estructure
寻找源代码,我到了这个:
1 .-主标题:主标题是 '导航' 标签中:
<nav id="headerMainMenu>
2.-在'nav'标签内部是一个'ul',里面的每个'il'对于9个部分中的每一个都有'id':
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
3.-的IL元素中,有包含我们需要的链接div元素:请注意<a>
与类= “subnav__title”。
<nav id="headerMainMenu>
<ul>
<il id = "category-item-celulares-y-tablets"><a href="...">
<div class="col-3">
<a href="..."class="subnav__title">TV y Video</a>
</il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
<il id = "category-item-celulares-y-tablets"><a href="..."></il>
</ul>
</nav>
4.-使用RSelenium去每个部分:
library(RSelenium)
library(rvest)
#start RSelenium
checkForServer()
startServer()
remDr <- remoteDriver()
remDr$open()
#navigate to your page
remDr$navigate("http://www.linio.com.pe/")
#Accesing the first submenu from "Category Celulares y Tablets
webElem <- remDr$findElement(using = 'css', value = "#category-item-celulares-y-tablets a.subnav__title")
webElem$sendKeysToElement(list(key = "enter"))
但这样做显示了这个错误:
> webElem$sendKeysToElement(list(key = "enter"))
Error: Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
*我觉得这question可能是帮帮我。但我不明白。
**我认为我的CSS是好的。
感谢您的试用,@MatZeg。我认为翠有答案。我需要测试它才能给他充分的信用。但是,谢谢! –