【问题标题】:How to find a dynamic elements using selenium webdriver?如何使用 selenium webdriver 查找动态元素?
【发布时间】:2020-05-18 11:04:19
【问题描述】:
<div id="button" data-testid="widgetButton" class=" chat-closed mobile-size__large">

我的元素带有 Webdriver 无法找到的特殊字符。

我正在尝试单击一个项目,我已经尝试了所有方法。 我的最后一次尝试:

wd.get(urlSubpage);
        wd.findElement(By.cssSelector("[class='widgetLabel']"));

【问题讨论】:

  • 尝试使用 ChroPath 之类的东西进行部分调试...
  • 您要查找哪个元素?
  • html中没有widgetLabel类。
  • @Muzzamil 我想找到

标签: java html selenium selenium-webdriver selenium-ide


【解决方案1】:

您可以在id 的帮助下使用 webdriver 等到元素能够接收到点击。

WebDriverWait wait = new WebDriverWait(driver, 50);

wait.until(ExpectedConditions.elementToBeClickable(By.id("button-body")));

用JS点击

WebElement element = driver.findElement(By.id("button-body"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

【讨论】:

  • 我加了但是Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: #button\-body
  • @Nirwellyn 请尝试点击答案中提到的 JS。复制粘贴代码并尝试。删除点击前的等待元素
猜你喜欢
  • 2017-07-03
  • 2014-07-18
  • 2023-01-22
  • 2017-09-12
  • 1970-01-01
  • 2023-01-25
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
相关资源
最近更新 更多