Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea not working with Firefox #470

Open
ylavoie opened this issue Mar 28, 2021 · 4 comments
Open

Textarea not working with Firefox #470

ylavoie opened this issue Mar 28, 2021 · 4 comments

Comments

@ylavoie
Copy link
Contributor

ylavoie commented Mar 28, 2021

We are doing tests using a Selenium hub latest (3.141.59) and multiple browsers. Although Chrome & Opera works perfectly Firefox hangs while trying to get a value from a TEXTAREA. Even the old PhantomJS works on standalone

We are using S::R::D 1.42 and here is the debug log from the driver with Firefox:

( STDOUT )  job  1    Prepping findChildElements
( STDOUT )  job  1    Executing findChildElements
( STDOUT )  job  1    REQ: POST, http://fileserver:4444/wd/hub/session/2726bbaf-34ba-4652-ba6e-fcb2e5cf145c/element/6da077d3-7edc-424e-bf76-69f13b4fb833/elements, {"value":".//*[@id=\"description_1\"]\n           | .//input[@type=\"hidden\" and\n                      @name=\"description_1\"]","using":"xpath"}
( STDOUT )  job  1    RES: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"3be07cbd-601c-445f-9ce6-a7930136ed28"}]}
( STDOUT )  job  1
( STDOUT )  job  1    Prepping getElementTagName
( STDOUT )  job  1    Executing getElementTagName
( STDOUT )  job  1    REQ: GET, http://fileserver:4444/wd/hub/session/2726bbaf-34ba-4652-ba6e-fcb2e5cf145c/element/3be07cbd-601c-445f-9ce6-a7930136ed28/name, {}
( STDOUT )  job  1    RES: {"value":"textarea"}
( STDOUT )  job  1
( STDOUT )  job  1    Prepping getElementAttribute
( STDOUT )  job  1    Executing getElementAttribute
( STDOUT )  job  1    REQ: GET, http://fileserver:4444/wd/hub/session/2726bbaf-34ba-4652-ba6e-fcb2e5cf145c/element/3be07cbd-601c-445f-9ce6-a7930136ed28/attribute/value, {}
( STDOUT )  job  1    RES: {"value":""}

The same test using chrome gives the desired Part 1 value.

( STDOUT )  job  1    Prepping findChildElements
( STDOUT )  job  1    Executing findChildElements
( STDOUT )  job  1    REQ: POST, http://fileserver:4444/wd/hub/session/ac2cf3c2e22d853a8daf1e003f2b420d/element/9234e571-23fa-4021-ace6-66e6e7ccb0e3/elements, {"using":"xpath","value":".//*[@id=\"description_1\"]\n           | .//input[@type=\"hidden\" and\n                      @name=\"description_1\"]"}
( STDOUT )  job  1    RES: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"721b28f6-aca8-444e-b2d6-a28d4c07b95b"}]}
( STDOUT )  job  1
( STDOUT )  job  1    Prepping getElementTagName
( STDOUT )  job  1    Executing getElementTagName
( STDOUT )  job  1    REQ: GET, http://fileserver:4444/wd/hub/session/ac2cf3c2e22d853a8daf1e003f2b420d/element/721b28f6-aca8-444e-b2d6-a28d4c07b95b/name, {}
( STDOUT )  job  1    RES: {"value":"textarea"}
( STDOUT )  job  1
( STDOUT )  job  1    Prepping getElementAttribute
( STDOUT )  job  1    Executing getElementAttribute
( STDOUT )  job  1    REQ: GET, http://fileserver:4444/wd/hub/session/ac2cf3c2e22d853a8daf1e003f2b420d/element/721b28f6-aca8-444e-b2d6-a28d4c07b95b/attribute/value, {}
( STDOUT )  job  1    RES: {"value":"Part 1"}

Because 3 browsers are working, we do suspect Firefox. Any suggestion for a workaround?

@teodesian
Copy link
Owner

Strong suspicion this is related to what is happening in #468.

You should probably use a javascript workaround:

$element->execute_script(qq{
    var elem = arguments[0];
    return elem.value;
});

If that still fails, then there's something seriously wrong with firefox driver. I guess the layoffs have really done a number on mozilla.

@ylavoie
Copy link
Contributor Author

ylavoie commented Mar 29, 2021

It works perfectly well with the polyfill so, as we both guessed, the Firefox driver has to be the problem.

@ylavoie ylavoie closed this as completed Mar 29, 2021
@ylavoie ylavoie reopened this Mar 30, 2021
@ylavoie
Copy link
Contributor Author

ylavoie commented Apr 2, 2021

The final answer was not to polyfill WebElement but the fact that Chrome & Opera (same engine) and thus most probably Microsoft Edge now, do fallback on get_attribute when get_property fails.

For JSONWIRE compatibility, we were calling get_attribute($element,1) to force it even on WD3 enabled browsers. The final solution was this:

sub get_attribute {
    my ($self, $id, $att) = @_;

    my $element = $self->_resolve_id($id);  # Get the WebElement
    my $value;
    $value = $element->get_attribute($att)  # Try with property/attribute
        if $self->_driver->{is_wd3};
    return $value
        // $element->get_attribute($att,1); # Force using attribute
}

That fixed it for Firefox and allowed us to test with it, along with Chrome, Opera and even PhantomJS

@teodesian
Copy link
Owner

In retrospect the "do exactly what the user requests" approach clearly was the wrong one, what everyone actually wants is DWIM, and the browser drivers themselves have embraced that. So, I will simply rip out this bit and make it DWIM by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants