Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to assert text of the input in selenium webrdriver – python

I’m starting to learn automated testing and I don’t know how to assert input text i selenium webrdiver in python. Could You help me?

This is my code – but it doesn’t work properly

def assert_element_text(self, driver, xpath, expected_text):
        element = driver.find_element(by=By.XPATH, value=xpath)
        element_text = element.text
        assert expected_text == element_text
   
 def assert_surname(self):
        self.assert_element_text(self.driver, self.surname_field_xpath, self.expected_surname)

I have assertion error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I also use robot framework and ‘Textfield Value Should Be’ works in that case.

>Solution :

Try to get value of input element, by:

element = driver.find_element(by=By.XPATH, value=xpath)
element_text = element.get_attribute("value")
assert expected_text == element_text
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading