Selenium Python I get an empty string from a text element, but there is a value in the GUI

I have text displayed in a GUI. I identified the element using its XPATH from Xpath Checker from Firebug. The item is highlighted correctly. In my code, I use a text attribute to print its value. I would like to print the value on the console. When I view the code using the PyCharm debugger, I see that the attribute of the variable text is empty. Why didn't the variable get a text value?

My code snippet:

def is_engine_number_displayed(self):
    engine_no_element = self.get_element(By.XPATH, '//a[contains(., "Engine: 5.1.1")]')
    print "engine_no_element.text***"
    print engine_no_element.text
    #return engine_no_element.text in "Engine: 5.1.1"

HTML:

<div class="GJPPK2LBKQ">
<a class="gwt-Anchor GJPPK2LBMQ" title="Click for about">Client: 5.1.1.6044</a>
<a class="gwt-Anchor GJPPK2LBMQ" title="Click for about">Engine: 5.1.1.5218</a>

My XPATH to find the text Engine: 5.1.1

//a[contains(., "Engine: 5.1.1")]

Using XPATH, Engine: 5.1.1 text is highlighted in a graphical interface

get_element is in my base class. This is the implementation:

# returns the element if found
def get_element(self, how, what):
    # params how: By locator type
    # params what: locator value
    try:
        element = self.driver.find_element(by=how, value=what)
    except NoSuchElementException, e:
        print what
        print "Element not found "
        print e
        screenshot_name = how + what + get_datetime_now() # create screenshot name of the name of the element + locator + todays date time.  This way the screenshot name will be unique and be able to save
        self.save_screenshot(screenshot_name)
        raise
    return element

Why is my text element value empty?

Thanks Riaz

+4
1

, . , , , . , , , , value ( ) - , getText() . value . , , , getText() . , "" -.

0

Source: https://habr.com/ru/post/1629225/


All Articles