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.edureka.co/");
        driver.findElement(By.xpath("//a[@href='https://www.edureka.co/selenium-certification-training']")).click();
    }
}

I am getting an error saying that element not found.
 

Jan 21, 2019 in Selenium by Rishab
• 1,490 points
724 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.edureka.co/");
        Thread.sleep(5000);
        driver.findElement(By.xpath("//a[@href='https://www.edureka.co/selenium-certification-training']")).click();
    }
}
answered Jan 21, 2019 by Priyaj
• 58,020 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, 2019 in Selenium by Dushyant
3,649 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 30, 2018 in Selenium by Damon Salvatore
• 5,980 points
5,356 views
0 votes
2 answers

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,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 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
• 58,020 points
24,139 views
+1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP