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, 2019 in Selenium by Rishab
• 1,490 points
705 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, 2019 by Priyaj
• 58,100 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,602 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,293 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,568 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,084 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,178 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,840 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,100 points
24,068 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