Skip to content

Commit 5bbbff6

Browse files
committed
Using get_text() on a textarea should return the value
1 parent b58b4cd commit 5bbbff6

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,9 @@ def is_text_visible(self, text, selector="html", by="css selector"):
10081008
selector, by = self.__recalculate_selector(selector, by)
10091009
if self.__is_shadow_selector(selector):
10101010
return self.__is_shadow_text_visible(text, selector)
1011-
return page_actions.is_text_visible(self.driver, text, selector, by)
1011+
return page_actions.is_text_visible(
1012+
self.driver, text, selector, by, self.browser
1013+
)
10121014

10131015
def is_attribute_present(
10141016
self, selector, attribute, value=None, by="css selector"
@@ -1429,6 +1431,8 @@ def get_text(self, selector, by="css selector", timeout=None):
14291431
element_text = element.get_attribute("innerText")
14301432
if element.tag_name == "input":
14311433
element_text = element.get_property("value")
1434+
if element.tag_name == "textarea":
1435+
element_text = element.get_property("value")
14321436
except (StaleElementReferenceException, ENI_Exception):
14331437
self.wait_for_ready_state_complete()
14341438
time.sleep(0.14)

seleniumbase/fixtures/page_actions.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,25 @@ def is_element_enabled(driver, selector, by="css selector"):
112112
return False
113113

114114

115-
def is_text_visible(driver, text, selector, by="css selector"):
115+
def is_text_visible(driver, text, selector, by="css selector", browser=None):
116116
"""
117-
Returns whether the specified text is visible in the specified selector.
117+
Returns whether the text substring is visible in the given selector.
118118
@Params
119119
driver - the webdriver object (required)
120-
text - the text string to search for
120+
text - the text string to search for (required)
121121
selector - the locator for identifying the page element (required)
122122
by - the type of selector being used (Default: By.CSS_SELECTOR)
123123
@Returns
124124
Boolean (is text visible)
125125
"""
126126
try:
127127
element = driver.find_element(by=by, value=selector)
128-
return element.is_displayed() and text in element.text
128+
element_text = element.text
129+
if element.tag_name == "input" or element.tag_name == "textarea":
130+
element_text = element.get_property("value")
131+
elif browser == "safari":
132+
element_text = element.get_attribute("innerText")
133+
return element.is_displayed() and text in element_text
129134
except Exception:
130135
return False
131136

@@ -470,7 +475,7 @@ def wait_for_text_visible(
470475
try:
471476
element = driver.find_element(by=by, value=selector)
472477
is_present = True
473-
if element.tag_name == "input":
478+
if element.tag_name == "input" or element.tag_name == "textarea":
474479
if (
475480
element.is_displayed()
476481
and text in element.get_property("value")
@@ -574,7 +579,7 @@ def wait_for_exact_text_visible(
574579
try:
575580
element = driver.find_element(by=by, value=selector)
576581
is_present = True
577-
if element.tag_name == "input":
582+
if element.tag_name == "input" or element.tag_name == "textarea":
578583
if (
579584
element.is_displayed()
580585
and text.strip() == element.get_property("value").strip()
@@ -934,7 +939,12 @@ def wait_for_element_not_visible(
934939

935940

936941
def wait_for_text_not_visible(
937-
driver, text, selector, by="css selector", timeout=settings.LARGE_TIMEOUT
942+
driver,
943+
text,
944+
selector,
945+
by="css selector",
946+
timeout=settings.LARGE_TIMEOUT,
947+
browser=None,
938948
):
939949
"""
940950
Searches for the text in the element of the given selector on the page.
@@ -953,7 +963,7 @@ def wait_for_text_not_visible(
953963
stop_ms = start_ms + (timeout * 1000.0)
954964
for x in range(int(timeout * 10)):
955965
shared_utils.check_if_time_limit_exceeded()
956-
if not is_text_visible(driver, text, selector, by=by):
966+
if not is_text_visible(driver, text, selector, by=by, browser=browser):
957967
return True
958968
now_ms = time.time() * 1000.0
959969
if now_ms >= stop_ms:

0 commit comments

Comments
 (0)