Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Click on invisible element fails in Chrome but Agouti ignores error and returns success #186

Open
hasryan opened this issue May 24, 2019 · 0 comments

Comments

@hasryan
Copy link

hasryan commented May 24, 2019

I wrote a test that attempted to click on an invisible element, and was surprised to find that the click did not return an error.

Example:

With this html:

<html><a id="foo" style="display:none">Invisible link</a></html>

This passes:

var page *agouti.Page
...
Expect(page.FindById("foo").Click()).To(Succeed())

The issue appears to be that Agouti expects ChromeDriver to indicate errors with a non-2XX status code, while (at least my version of ChromeDriver) returns HTTP 200 even when a failure occurred.

I added some debug statements and found that the response from ChromeDriver does report this click error using the status property of the response as described here: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#response-status-codes

For the above example, it responded with the body:

{
  "sessionId": "...",
  "status": 11,
  "value": {"message":"element not interactable\\n (Session info: ..."}
}

My analysis:

When the click request is sent here:

return e.Send("POST", "click", nil, nil)

It does not provide a pointer for the response.
Which results in the client not attempting to parse the response (aside from checking HTTP status code):
if result != nil {

My fix replaced the following block of code from

if result != nil {
bodyValue := struct{ Value interface{} }{result}
if err := json.Unmarshal(responseBody, &bodyValue); err != nil {
return fmt.Errorf("unexpected response: %s", responseBody)
}
}

With this in its place:

bodyValue := struct{
	Status int `json:"status"`
	Value interface{} `json:"value"`
}{}
if result != nil {
	bodyValue.Value = result
}

if err := json.Unmarshal(responseBody, &bodyValue); err != nil {
	return fmt.Errorf("unexpected response: %s", responseBody)
} else if bodyValue.Status != 0 {
	return fmt.Errorf("unexpected response (nonzero status %d): %s", bodyValue.Status, responseBody)
}

I am not sure if this is an issue with ChromeDriver not not returning the correct HTTP status code, or if it's reporting errors in a valid way. For this reason I am not sure if it's safe to make this change or if it could cause issues with other browser drivers.

I am using ChromeDriver v 2.46 on macOS

@hasryan hasryan changed the title Click error from WebDriver not reported Click on invisible element fails in Chrome but Agouti ignores error and returns success Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant