'Why I am unable to find and click the button/anchor element from a page?

I've been trying to click the button/anchor element from the Bydureon Page and here is my simple code:

public class RoughTest {

    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeMethod(alwaysRun = true)
    private void setUp() {
        System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        wait = new WebDriverWait(driver, 5);
    }

    @Test
    public void roughTest() throws InterruptedException {

        driver.get("https://www.bydureon.com/bydureon-bcise.html");
        WebElement button = driver.findElement(
                  By.xpath("(//div[@id='doctor-discussion-guide']//a[1]"));
        wait.until(ExpectedConditions.elementToBeClickable(button));
        button.click();
        Thread.sleep(1000);
    }

    @AfterMethod(alwaysRun = true)
    private void tearDown() {
        // close browser
        driver.quit();
    }
}

Tried using multiple ways to locate it but no luck.

//div[@id='doctor-discussion-guide']//a[1]
//a[@href='/content/dam/intelligentcontent/brands/byd/global/about/US-56308-BCI-Doctor-Discussion-Guide.pdf']
(//a[@class='cmp-teaser__action-link'][normalize-space()='Get 4 Key Questions'])[1]
//a[contains(text(),'Get 4 Key Questions')]

Always getting the below exception:

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable

Here is the HTML code of the element

<div class="cmp-teaser__action-container" xpath="1">
<a class="cmp-teaser__action-link" href="/content/dam/intelligentcontent/brands/byd/global/about/US-56308-BCI-Doctor-Discussion-Guide.pdf" style="">
Get 4 Key Questions
<span class="cmp-teaser__actionicon">
<img>
<span></span>
</span>
</a>
<a class="cmp-teaser__action-link" href="/content/dam/intelligentcontent/brands/byd/global/about/US-56308-BCI-Doctor-Discussion-Guide.pdf">
Get 4 Key Questions
<span class="cmp-teaser__actionicon">
<img>
<span></span>
</span>
</a>
</div>

This is how the element visible in the page:

Get 4 Key Questions



Solution 1:[1]

At last, with the help of JavascriptExecutor able to click the element, so here is my code:

public class RoughTest {

    private WebDriver driver;
    private JavascriptExecutor jse;

    @BeforeMethod(alwaysRun = true)
    private void setUp() {
        System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        jse = (JavascriptExecutor)driver;
    }

    @Test
    public void roughTest() throws InterruptedException {

        driver.get("https://www.bydureon.com/bydureon-bcise.html");
        WebElement button = driver.findElement(By.xpath("(//a[@class='cmp-teaser__action-link'])[3]"));
        
        jse.executeScript("arguments[0].click()", button);
        
        Thread.sleep(1000);
    }

    @AfterMethod(alwaysRun = true)
    private void tearDown() {
        // close browser
        driver.quit();
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Satheesh47