css - RSelenium 找到并点击链接
问题描述
我下面的代码向日本地理定位网站发送请求,并获得一个新页面,但我无法让 RSelenium 定位并单击该链接。
library(XML)
library(RSelenium)
remDr <- remoteDriver(
remoteServerAddr = "localhost",
port = 4445L,
browserName = "firefox"
)
remDr$open()
remDr$navigate("https://maps.gsi.go.jp")
remDr$screenshot(display = TRUE)
remDr$getCurrentUrl()
webElem <- remDr$findElement(using = "id", value = "query")
webElem$getElementAttribute("id")
webElem$highlightElement()
webElem$sendKeysToElement(list("茨城県行方郡玉造町","\uE007"))
remDr$screenshot(display = TRUE)
我想单击下面的节点并从新页面获取 URL,但我的尝试remDr$findElement
都没有奏效。我错过了一些明显的东西吗?
<a href="javascript:void(0);" style="padding-left: 32px; background: url("image/mapicon/search_result.png") 0px 50% no-repeat;"><div class="title">茨城県行方郡</div><div class="muni">茨城県行方市</div></a>
解决方案
像这样?
link <- remDr$findElement(using = "css selector", value = ".muni")
link$highlightElement()
link$clickElement()
remDr$getCurrentUrl()
推荐阅读
- python - cStringIO.StringIO 和 io.BytesIO 在 Python 2 中可以互换吗?
- javascript - 我在从单个下拉列表中输出 2 个值时遇到问题
- mysql - 使用 Spring 数据 JPA 和 MySQL 运行 SpringBoot 应用程序时出错
- xml - XSLT - 如何使用模板匹配有条件地对元素进行分组
- python-3.x - 多线程时如何控制内存消耗
- python - 验证元胞自动机中的幂律
- python - 如何限制 SQLAlchemy + Pandas 操作中的 RAM 消耗?
- node.js - SSL 证书和域访问行为异常
- firebase - 本地通知与 FCM:哪个是正确的?
- javascript - 如何进行随机突变