1

I'm parsing the website "https://www.diretta.it" with Selenium library. When I try to click a link after another click, there is no results.

This is the Code:

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();
    }

This part of the code is as if it were not executed

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

This is the link that I would to click:

enter image description here

1 Answers1

1

This is a dynamic element, so you will need to induce a web driver wait:

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();

with the imports:

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77