gpt4 book ai didi

java - selenium - 不可点击的链接

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

我正在解析网站"https://www.diretta.it"与 Selenium 库。当我再次点击一个链接时,没有结果。

这是代码:

public static void main(String[] args)
{
String url = "https://www.diretta.it/serie-a-2016-2017/";

// System Property for Chrome Driver
System.setProperty("webdriver.chrome.driver","C:\\..\\chromedriver_win32\\chromedriver.exe");

// Instantiate a ChromeDriver class.
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();

driver.get(url);
driver.findElement(By.xpath("//a[@href='/serie-a-2016-2017/risultati/']")).click();

try
{
Thread.sleep(3000); // 3 secondi
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

这部分代码就像没有执行过

    WebElement element = driver.findElement(By.xpath("//a[@class='event__more event__more--static']"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
}

这是我要点击的链接:

enter image description here

最佳答案

这是一个动态元素,因此您需要引发网络驱动程序等待:

WebDriverWait wait = new WebDriverWait(driver, 30);
String xpath = "//a[@class='event__more event__more--static']";
WebElement link = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xpath));

link.click();

导入:

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

关于java - selenium - 不可点击的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57711143/

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