gpt4 book ai didi

java - Selenium WebDriver java

转载 作者:行者123 更新时间:2023-12-01 10:26:32 25 4
gpt4 key购买 nike

我正在使用 Mozilla firefox 44.0.1 和 java 版本 1.8 和 selenium 版本 2.48

我正在使用以下Web Page

我需要选择一个商品并按“我想购买此商品”按钮,这会创建购物篮区域有 1 件商品。一旦您添加,右上角的购物篮就会更新。你会看到:

1 item/s View Basket

我在定位该项目时遇到问题,并且收到“无法定位元素”错误。我有以下行来定位元素:

String count = driver.findElement(By.id("buyBasketCount")).getText();

我尝试过:

String count = driver.findElement(By.xpath("//div[@class='buyBasketContent']/td[1]/span")).getText();

如何访问该元素?我正在尝试获取变量计数返回的值。但我无法找到元素。

如何访问页面中的此元素?

最佳答案

您可以使用Thread.sleep(输入以毫秒为单位的时间),但这绝不是推荐的方式。

不如使用这个:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("buyBasketCount")));
String count = driver.findElement(By.id("buyBasketCount")).getText();

关于java - Selenium WebDriver java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35331887/

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