Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Python and how to do getText() from an element/seclector

  • 21-09-2015 2:59pm
    #1
    Registered Users, Registered Users 2 Posts: 262 ✭✭


    I’m looking to take a value from a text field to do some arithmetic on

    hour_value = str(browser.find_element("logviewer_hour_text_field", 30))
    log.logger.info("Hour now {0}".str(hour_value.text))


    My output from the element is “None” when I run it. Basically am looking for the equivalent of textField.getText() in Java.

    Do you have any simple examples of getting text from 1 element/selector.


Comments

  • Registered Users, Registered Users 2 Posts: 3,739 ✭✭✭johnmcdnl


    Assuming this is using Selenium WebDriver?
    I'm not overly familar with Python but I don't think you should be wrapping the element with the str() as that will convert the element object to a string which is probably unreadable.

    hour_value = str(browser.find_element("logviewer_hour_text_field", 30))
    log.logger.info(hour_value )

    Have a look at what that prints out - it's probably a long string that means nothing to you. (This is assuming that str() behaves similaring to the .toString() methods in Java.)



    What I think you may need is something along the lines of:

    hour_value = browser.find_element("logviewer_hour_text_field", 30)
    log.logger.info(hour_value.text)


    Once again I don't think you should need to wrap it with str() as .text should return a String in the first place.

    Apologies if this is no use to you - as I said I'm not really that familiar with Python.


  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭PrzemoF


    What's behind that "browser' thing?

    >>> import browser
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named browser

    What returns (type and value) browser.find_element? If it's None you won't be able to squeze anything out of it.


  • Registered Users, Registered Users 2 Posts: 339 ✭✭duffman85


    As per johnmcdnl's post, I'm assuming you're using selenium webdriver.
    I think John has you on the right track but for more info - see the selenium api docs http://selenium-python.readthedocs.org/en/latest/api.html#module-selenium.webdriver.remote.webelement


Advertisement