【问题标题】:CSS selector doesn't work when using Rselenium使用 Rselenium 时 CSS 选择器不起作用
【发布时间】:2019-06-08 07:02:18
【问题描述】:

我需要使用 Rselenium 抓取网站,但我遇到了问题 - 没有使用 css 选择器解析带有登录名和密码的字段

首先,我设置了与远程服务的连接并导航到我感兴趣的网站。在处理所需的信息之前,我必须登录。我已经在另一个网站上完成了类似的操作,没有任何问题。现在 findElement 函数不适用于这些元素(登录名和密码字段),尽管可以轻松搜索此页面上的其他元素

remDr <- RSelenium::remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L)

remDr$open()

remDr$navigate("https://aisrzn.ru/login/")

remDr$getTitle()

webElem <- remDr$findElement("css", "#menu-item-7476 > a > span > span") # here everything is okay

这是有问题的元素,我发现选择器看起来很奇怪:

webElem <- remDr$findElement("css", ".fieldsLayout > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > input:nth-child(1)") 

Selenium 消息:无法定位元素:.fieldsLayout > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > 输入:第n个孩子(1) 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.14.0',修订:'aacccce0',时间:'2018-08-02T20:13:22.693Z' 系统信息:主机:'0c3a6ca7c648',ip:'172.17.0.2',os.name:'Linux',os.arch:'amd64',os.version:'4.9.93-boot2docker',java.version:' 1.8.0_181' 驱动信息:driver.version:未知

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

我只需要通过 Rselenium 登录即可继续使用该站点。现在我被堆积并寻求帮助。我的猜测是注册表单有问题 - 包含在此块中的任何元素都不会被解析。有谁知道如何解决这个问题?

附:还有另一个具有相同信息的网站,但我放弃了使用此功能,因为导航功能无法使用它:

https://rzn.mos.ru/

【问题讨论】:

标签: r rselenium


【解决方案1】:

您应该为有问题的行中的一个字符串切换到单引号。这些都可以工作:

# Single quotes around the long outer string
webElem <- remDr$findElement("css", '#paneContent > form > div:nth-child(4) > table > tbody > tr:nth-child(1) > td > input[type="text"]') 

# Single quotes around the short inner string
webElem <- remDr$findElement("css", "#paneContent > form > div:nth-child(4) > table > tbody > tr:nth-child(1) > td > input[type='text']") 

【讨论】:

  • 嗨!感谢您的帮助,但不幸的是,这些选项都不起作用。这是错误:Selenium 消息:无法找到元素:#paneContent > form > div:nth-child(4) > table > tbody > tr:nth-child (1) > td > input[type='text'] 错误:摘要:NoSuchElement 详细信息:使用给定的搜索参数无法在页面上找到元素。类:org.openqa.selenium.NoSuchElementException 更多细节:运行errorDetails方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-07
  • 1970-01-01
  • 2017-06-04
  • 2020-04-21
相关资源
最近更新 更多