Wait related question

Interview question :

We have a button on a web page, we have written automated script to click it,but script gets failed at run time on click statement of button

But when we manually opens the page button is clickable

Also the button is visible when script is running

What would be the reason of click failure and how u will tackle it ?

amitjain Supporter Asked on March 27, 2015 in Selenium WebDriver.
Add Comment
2 Answer(s)

The code will fail when the locator is not matching.

udhaya Default Answered on March 27, 2015.
Add Comment

Basically what we are trying to solve here is whether the element is enabled or not. Element can be visible but enabled. To approach these kinds of question you have to start with asking
1. Is there any exception that is thrown? Answer: There has to be  some exception that will be raised and based on that we have to take action. If there is something related to element not enabled we have to check for following condition

WebElement.isEnabled() && WebElement.isDisplayed

Now one you have figured out that its the isEnabled property that is changing for the webElement we can put a simple smart wait like this

WebDriverWait wait = new WebDriverWait(driver, 8000);
wait.until(ExpectedConditions.elementToBeClickable(<Element locator here>);

This  should solve the problem

Virender

Virender Singh Professor Answered on March 27, 2015.

Button is inside a frame ….. so it is enable can be seen on UI
Manually can be clicked but if we click it using locator it will not be clicked
because it’s inside a frame

Virender sir if I pass my locator in below command without switching to frame will that work. I think it will not work because this command returns true saying button is clickable

WebDriverWait wait = new WebDriverWait(driver, 8000);
wait.until(ExpectedConditions.elementToBeClickable(<Element locator here>);

on March 29, 2015.

You have to switch to the frame, it wont work other wise. Try after switching.

on March 31, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.