teodesian / Selenium-Remote-Driver

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

get_text() not working #468

Open CJohnno77 opened 3 years ago

CJohnno77 commented 3 years ago

I have found that get_text() is not working and just returns blank string and I have to do get_attribute('innerText') instead to get the text. I have version 1.42 installed.

$lang_text = $selen->find_child_element($lang_elem, './/span[@class="odsTitle"]')->get_attribute('innerText'); # this works
$lang_text2 = $selen->find_child_element($lang_elem, './/span[@class="odsTitle"]')->get_text;  # this doesn't
teodesian commented 3 years ago

cool. Can you give me the output of what happens when you execute

$driver->debug_on()

before you execute these statements?

I want to know if this is an upstream driver problem, or something due to S::R::D.

(It's probably the former, in which case I'll have to make yet another polyfill, yay)

CJohnno77 commented 3 years ago

I think this is what you're after:

Prepping findChildElement
Executing findChildElement
REQ: POST, http://devserv3:4444/wd/hub/session/1f2f51b4-122a-4d52-abb6-5d8d69402a5a/element/ccfcecd4-5479-42f2-af8b-487f79110013/element, {"value":".//span[@class=\"odsTitle\"]","using":"xpath"}
RES: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0b70bc7c-0f1c-4e7a-80de-3bcc8213b17b"}}

Prepping getElementProperty
Executing getElementProperty
REQ: GET, http://devserv3:4444/wd/hub/session/1f2f51b4-122a-4d52-abb6-5d8d69402a5a/element/0b70bc7c-0f1c-4e7a-80de-3bcc8213b17b/property/innerText, {}
RES: {"value":"ARABIC"}

Prepping findChildElement
Executing findChildElement
REQ: POST, http://devserv3:4444/wd/hub/session/1f2f51b4-122a-4d52-abb6-5d8d69402a5a/element/ccfcecd4-5479-42f2-af8b-487f79110013/element, {"value":".//span[@class=\"odsTitle\"]","using":"xpath"}
RES: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0b70bc7c-0f1c-4e7a-80de-3bcc8213b17b"}}

Prepping getElementText
Executing getElementText
REQ: GET, http://devserv3:4444/wd/hub/session/1f2f51b4-122a-4d52-abb6-5d8d69402a5a/element/0b70bc7c-0f1c-4e7a-80de-3bcc8213b17b/text, {}
RES: {"value":""}
teodesian commented 3 years ago

Indeed it is. Thank you.

So, as usual it's misbehavior from the upstream driver. I guess I'll just turn it into a polyfill wrapping getElementProperty.

CJohnno77 commented 3 years ago

OK, just out of curiosity, what do you mean by "polyfill wrapping" ?

teodesian commented 3 years ago

There are a number of subroutines in S::R::D that work around misbehaving drivers, or implement functionality from JSONWire which is missing in WC3 selenium.

In this case I'd just make getElementText execute javascript and return element.innerText().

In my experience, selenium drivers are so unreliable that you may as well just flush it down the toilet and write javascript; this is why I advocate using Playwright instead these days. I've written a perl client for Playwright if you prefer to continue writing perl.