【问题标题】:Selenium | Unable to locate the element error硒 |无法定位元素错误
【发布时间】:2021-05-31 15:44:09
【问题描述】:

我使用了许多定位器组合,但仍然出现 element not found 错误。这是元素

<div id="mailmillieu">
  <div>
   <div style="padding:8px"></div>
  </div>
  <div>
    Hi, here is your otp :  216570
  </div>
</div>

我只想提取 otp,仅此而已。非常感谢任何帮助。

【问题讨论】:

    标签: selenium selenium-webdriver css-selectors


    【解决方案1】:

    您可以使用#mailmillieu &gt; div:nth-child(2) css 定位器,然后在其上使用 getText()。 在你得到的字符串上,你可以提取数字来得到 OTP 值。

    【讨论】:

    • 我之前尝试过,但我仍然收到错误 org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector", "选择器":"#mailmillieu > div:nth-child(2)"}
    • @sparshbhardwaj 你能检查你是否在正确的框架?
    • 我相信我在正确的框架中。但我不确定你所说的框架是什么意思
    • 如果这段代码在iframe里面,先切换到frame再读取值。 guru99.com/handling-iframes-selenium.html
    猜你喜欢
    • 2020-07-23
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    相关资源
    最近更新 更多