【问题标题】:how to locate the element in <div aria-label>如何定位 <div aria-label> 中的元素
【发布时间】:2021-06-19 08:00:02
【问题描述】:

我是 selenium java 的初学者。我正在尝试在亚马逊中找到该元素。

当我尝试运行此代码时,我找不到该元素。请帮助解决这个问题。

enter image description here

这是我的代码

    WebElement a_review= driver.findElement(By.xpath("//div[@aria-label='4 Stars & Up']"));
            ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", a_review);
            a_review.click();

【问题讨论】:

标签: javascript java html selenium findelement


【解决方案1】:

在这里您可以简单地单击元素而无需使用 javascript。请尝试以下代码:

driver.get("https://www.amazon.in/s/ref=mega_sv_s23_1_2_1_2?rh=i%3Ashoes%2Cn%3A1983633031&ie=UTF8&lo=shoes");
driver.findElement(By.xpath("//div[@aria-label='4 Stars & Up']")).click();

【讨论】:

  • 非常感谢分享。它工作得很好。
猜你喜欢
  • 2018-03-22
  • 1970-01-01
  • 2021-03-21
  • 2017-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多