Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have a problem with my tests in Selenium WebDriver. The Click event not always works when a program tries to click on button. In one test everything is ok, in others it is not.

Every test starts on one page. First, the user has to choose an option from a select component and after that, the user clicks on a button.

I want to know why one time everything is ok, and when I run tests a second time it is not?

Here is the source code of finding and clicking the button:

public void clickContinueBtn() {    

    webElement = driver.findElement(By.xpath("//div[@class='btn magenta_s']/a/span"));

    webElement.click(); 

}

1 Answer

0 votes
by (62.9k points)

Often it occurs mainly because of Browser compatibility (Mostly on firefox). So try to use "WebElement.sendKeys(Keys.ENTER);" code in place of "webElement.click(); "

Or, you can try using  Action Class:

WebElement element = driver.findElement("yourElement");

        Actions builder = new Actions(driver);

        builder.moveToElement(element).click(element);

        builder.perform();

Hope this helps!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...