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

get_text() not working #468

Open
CJohnno77 opened this issue Mar 24, 2021 · 5 comments
Open

get_text() not working #468

CJohnno77 opened this issue Mar 24, 2021 · 5 comments

Comments

@CJohnno77
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@teodesian
Copy link
Owner

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.

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

No branches or pull requests

2 participants