gpt4 book ai didi

java - 无法使用 Selenium 和 Java 单击 Flipkart 主页中图像 slider 中的图像之一

转载 作者:行者123 更新时间:2023-12-02 00:40:42 25 4
gpt4 key购买 nike

我使用下面的方法来单击 Flipkart 主页图像 slider 中的第二张图像,但我收到“Selenium.Timeout.Exception”。下面方法中提到的Xpath是为第二张图像编写的。如果你检查这个 xpath,它总是会突出显示第二个图像,但不管用下面的方法如何,我都无法单击第二个图像,尽管我已经验证该元素确实保留在 DOM 中一段时间​​,并且在那一刻只有它应该被点击,但无论如何它没有发生。

有人可以帮我解决这个问题吗?

  Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(120))
.pollingEvery(Duration.ofMillis(500))
//.ignoring(ElementClickInterceptedException.class);
.ignoring(TimeoutException.class);

Boolean element = wait.until(new Function<WebDriver, Boolean>(){

public Boolean apply(WebDriver driver) {

return driver.findElement(By.xpath("(//div[@class='_3ZUwcz'])[3]//descendant::div//img[@class='_2VeolH _3I5S6S']")).isDisplayed();

}

});
System.out.println("Actual Element visibility " +element);
if(element==true) {

driver.findElement(By.xpath((//div[@class='_3ZUwcz[3]//descendant::div//img[@class='_2VeolH_3I5S6S']")).click();

}

最佳答案

尝试单击该元素:

WebElement element = driver.findElement(By.xpath("(//div[@class='_3ZUwcz'])[3]//descendant::div//img[@class='_2VeolH _3I5S6S']"));
JavascriptExecutor js= (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);

关于java - 无法使用 Selenium 和 Java 单击 Flipkart 主页中图像 slider 中的图像之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943451/

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