gpt4 book ai didi

java - 如何通过 Java 使用 Selenium 定位文章标签内的按钮

转载 作者:行者123 更新时间:2023-11-30 05:36:21 25 4
gpt4 key购买 nike

我无法检测到以下代码文章中的按钮:

<article id="ride-f6ba24ca-d847-44b7-987e-81db6e6dee47" class="DetailPage__container--1VLdd"><div class="DetailPage__highlights--1uyrQ"><section></section><form aria-label="Offer highlights" class="DetailPage__section--qtXxV"><button type="submit"><span>Accept offer</span></button></form></div></article>

我尝试:

driver.findElement(By.xpath("//*[text()='Details']"))
driver.findElement(By.xpath("//button[.//span[text()='Accept offer']]"))

没有运气

我无法在java中检测到接受带有selenium的元素

最佳答案

所需的元素是动态元素,因此要找到该元素,您必须为 elementToBeClickable() 引入 WebDriverWait,并且您可以使用以下任一 Locator Strategies :

  • css选择器:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("article[class^='DetailPage__container--'][id^='ride-']>div[class^='DetailPage__highlights--'] button[type='submit']>span")));
  • xpath:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//article[starts-with(@class, 'DetailPage__container--') and starts-with(@id, 'ride-')]/div[starts-with(@class, 'DetailPage__highlights--')]//button[@type='submit']/span[text()='Accept offer']")));

关于java - 如何通过 Java 使用 Selenium 定位文章标签内的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56532470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com