teodesian / Selenium-Remote-Driver

Perl Bindings to the Selenium Webdriver server
174 stars 90 forks source link

Textarea not working with Firefox #470

Open ylavoie opened 3 years ago

ylavoie commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

ylavoie commented 3 years ago

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 commented 3 years ago

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.