HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected) while clicking element with IEDriverServer Selenium and Java

孤者浪人 提交于 2019-11-26 18:43:16

问题


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.

回答1:


This error message...

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.

...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:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("XPath for Element 1"))).click();

Additionally, you need to take care of the following aspects:

  • Protected Mode: On Internet Explorer 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings you have to choose "Internet Options" from the "Tools" menu and then click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled Enable Protected Mode.

@JimEvans in his article You're Doing It Wrong: IE Protected Mode and WebDriver clearly mentions :

Using the capability doesn't solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS in Java and IntroduceInstabilityByIgnoringProtectedModeSettings in .NET. We really thought that telling the user that using this setting would introduce potential badness in their code would discourage its use, but it turned out not to be so.

  • 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




回答2:


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.

Actions actions = new Actions(d1);
actions.moveToElement(clickurl).click().build().perform();

js.executeScript("arguments[0].click();",clickurl);

I used below question to reach at this conclusion - Selenium click not always working



来源:https://stackoverflow.com/questions/53723400/http-status-500-incorrect-json-status-mapping-for-timeout-408-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!