Click a button using selenium

0 votes
public class ButtonClick {
    public static void main(String[] args)
    {
        System.setProperty("webdriver.chrome.driver","C:\\Users\\Downloads\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.tutorialspoint.com");
        driver.findElement(By.xpath("//a[@href='https://store.tutorialspoint.com']")).click();
    }
}

I am getting an error saying that element not found.
 

Jan 21 in Selenium by Rishab
• 1,460 points
53 views

1 answer to this question.

+1 vote

Your code works fine here, the only possibility of you getting this error would be if you are searching for the element that is not yet displayed. Try adding a wait before searching for the element. Hope this will work.

public class ButtonClick {
    public static void main(String[] args) throws InterruptedException
    {
       System.setProperty("webdriver.chrome.driver","C:\\Users\\priyj_kumar\\Downloads\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.tutorialspoint.com");
        Thread.sleep(5000);
        driver.findElement(By.xpath("//a[@href='https://store.tutorialspoint.com']")).click();
    }
}
answered Jan 21 by Priyaj
• 56,940 points
@priyaj, But thread.sleep() is not a wait statement right? Which one should be used?

Related Questions In Selenium

0 votes
1 answer

Cannot click on a button using selenium

The error that I figured out was ...READ MORE

answered Jan 4 in Selenium by Dushyant
221 views
0 votes
1 answer

Double click a record in a grid using Selenium webdriver

Try Actions class to perform this Actions action ...READ MORE

answered Mar 29, 2018 in Selenium by Damon Salvatore
• 5,510 points
1,158 views
0 votes
1 answer

Click on a button within a pop-up window with python selenium

It's not an Alert but a Modal Dialog Box. You ...READ MORE

answered Jun 20, 2018 in Selenium by Samarpit
• 5,130 points
8,162 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
992 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,143 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
887 views
0 votes
2 answers

Unable to Click on an Element in Selenium (Python) even after finding it.

Here, I give you working script which ...READ MORE

answered Sep 19, 2018 in Selenium by Priyaj
• 56,940 points
8,846 views
0 votes
2 answers