page-objects icon indicating copy to clipboard operation
page-objects copied to clipboard

Question

Open cvega opened this issue 9 years ago • 3 comments

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?

cvega avatar May 12 '16 17:05 cvega

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

bikemule avatar Aug 04 '16 02:08 bikemule

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.

eeaston avatar Sep 08 '16 13:09 eeaston

Hi

I'll use this issue instead of creating new one. How can I check if particular PageElement is displayed?

klubi avatar Oct 12 '16 13:10 klubi