0
votes

I have a 'Next' button on every page of the web application under test. On the first page of the form I can select the Next element and click, in the second page, selecting and clicking the same element thrown an error:

-> error: Unexpected error. Element is not clickable at point (1007.5, 244.14999389648438). Other element would receive the click:

This is the HTML for the element: div class="submitarea" input class="back-button btn" type="button" value ="Back"> input class="trigger-next-button btn btn-primary" type="button" value ="Next"> input class="next-button btn btn-primary" type="button" value ="Next"> style="display: none;" /div>

This is the code to click the button:

var nextBTN = testhelper.FireFoxBrowser.FindElement(By.ClassName("trigger-next-button"));
nextBTN.Click();
2
When I add the following code to the step before this one: System.Threading.Thread.Sleep(6000) then it works. Does this mean it's a case of the webdriver trying to click before the page is fully loaded? If so is there any command in webdriver to wait for the page to load before continuing?Pixie

2 Answers

0
votes

Based on the fact that adding a Sleep works as expected, it sounds as though your code is getting ahead of the WebDriver. You'll need to perform some sort of syncing to keep them in tandem with each other. I'd utilize a staleness check here like so:

WebDriverWait wait = new WebDriverWait(driver, 60); // 60 is the time to wait, can be extended as needed. This is an 'up-to' wait and will not necessarily stop for 60 seconds.
    var nextBTN = testhelper.FireFoxBrowser.FindElement(By.ClassName("trigger-next-button"));
nextBTN.Click();
//Wait for that button to 'go away' before proceeding.
wait.until(ExpectedConditions.stalenessOf(nextBTN));
//Wait for another instance of the button to appear and be clickable before proceeding.
wait.until(ExpectedConditions.elementToBeClickable(By.ClassName("trigger-next-button")));
nextBTN = testhelper.FireFoxBrowser.FindElement(By.ClassName("trigger-next-button"));
nextBTN.Click();
wait.until(ExpectedConditions.stalenessOf(nextBTN));

See these for more information regarding wait'ing and Expected Conditions:

0
votes

This error usually comes when the button is either not in visible on current monitor view or element is not present or clickable. Try using the below code.

Webdriverwait wait = new webdriverwait(driver, 60);

Actions builder = new Actions(driver);

Webelement element = wait.until(ExpectedConditions.elementtobeclickable(By.xpath('xpath'));

Builder.movetoelement(element).click().perform();