page-objects
page-objects copied to clipboard
Question
I see your example of using text. If I assign text to the page object in your example, everything works fine. If I don't I just get None type. I want to extrapolate the text from the page object. Maybe I'm doing it wrong?
I'm not an expert on this and I'm not sure which part of the tutorial you're referring to, but I hate to see unanswered questions.
You can always access the driver directly: https://page-objects.readthedocs.io/en/latest/tutorial.html#accessing-the-webdriver-directly Something like this: some_page_object.w.find_element_by_id("the_form").text
Hi there, Sorry for the very slow reply and thanks @bikemule for helping out! @bikemule is correct you can always access the driver directly in the manner he described. To do this natively you'd define a page element on the page object, and access it's 'text' property.
For example the following html:
<html>
<head></head>
<body>
<div id="my-text-box">Lorum Ipsum</div>
</body>
</html>
Here's the python to access the text of the div box:
from page_objects import PageObject, PageElement
from selenium import webdriver
class MyPage(PageObject):
textbox = PageElement(id_='my-text-box')
driver = webdriver.PhantomJS()
p = MyPage(driver)
the_text = p.textbox.text
assert the_text == 'Lorum Ipsum'
If this doesn't work, the page element constructor might be incorrect and you're picking up the wrong element.
Hi
I'll use this issue instead of creating new one. How can I check if particular PageElement is displayed?