Below are the details related to my flow -
- Page - 1 - Login to Web page
- After login, a URL Appears (Lets call it Element 1)
- After clicking Element 1, web page loads again and there I need to click on a different element, (Lets call it Element 2).
Problem -
Driver gets stuck, either Element 1 is not getting clicked or after adding sufficient wait Element 1 gets clicked but now driver gets stuck at this flow as you can observe from below code, once clickurl.click()
is called then after 10 seconds I should get a message that "Sleep Completed.. Now we return to calling class"
But instead I get exception.
Code -
clickurl = d1.findElement(By.xpath("XPath for Element 1"));
if ( clickurl != null ) {
System.out.print("****** Clicking on it Directly ");
clickurl.click();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("****** Sleep Completed.. Now we return to calling class ");`
System Details -
- InternetExplorerDriver server (64-bit) 3.14.0.0
- Os name: 'Windows 10'
- Java version: '1.8.0_191'
Other Details -
- Please note that after clicking on Element 1, I use
driver.switchTo().defaultContent();
Error Details -
Dec 11, 2018 5:02:56 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected)
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out waiting for page to load.
After trying multiple things and waits and using the settings from above answer, I used below code i.e. Moving the mouse to element and the performing click operation.
I used below question to reach at this conclusion - Selenium click not always working
This error message...
...implies that the IEDriverServer was unable to perform
click()
on the element.HTTP Status: '500'
The HyperText Transfer Protocol (HTTP) 500 Internal Server Error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
This error response is a generic "catch-all" response. Sometimes, server administrators log error responses like the 500 status code with more details about the request to prevent the error from happening again in the future.
HTTP Status: '408'
408 REQUEST TIMEOUT indicates that the server did not receive a complete request message within the time that it was prepared to wait.
A server SHOULD send the "close" connection option in the response, since 408 implies that the server has decided to close the connection rather than continue waiting. If the client has an outstanding request in transit, the client MAY repeat that request on a new connection.
Solution
You need to induce WebDriverWait for the desired element to be clickable and you can use the following solution:
Additionally, you need to take care of the following aspects:
@JimEvans in his article You're Doing It Wrong: IE Protected Mode and WebDriver clearly mentions :
Browser Zoom Level: The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
Browser Focus: The challenge is that IE itself appears to not fully respect the Windows messages we send the IE browser window (WM_MOUSEDOWN and WM_MOUSEUP) if the window doesn't have the focus. Specifically, the element being clicked on will receive a focus window around it, but the click will not be processed by the element. Arguably, we shouldn't be sending messages at all; rather, we should be using the SendInput() API, but that API explicitly requires the window to have the focus.
You can find a detailed discussion in Single click in selenium acts as double click