0

I tried to use some assert statements but it everytime fails.

button_test1 = driver.find_elements_by_xpath('//*[@class="custom-select"]')[0]
button_test1.click()

time.sleep(2)

button_test2 = driver.find_elements_by_xpath('//*[contains(text(),"Box Sport Žilina")]')[0]
button_test2.click()

time.sleep(2)

element = driver.find_element_by_xpath('//*[contains(text(),"Box Sport Žilina")]').text

time.sleep(2)

assert element == "Box Sport Žilina"
Luke Teensie
  • 21
  • 1
  • 5

2 Answers2

0

The contains in the xpath means you will get a partial match

<div>Box Sport Žilina some more text<div>

Or even with a blank space

<div> Box Sport Žilina<div> <!-- the text is equal to ' Box Sport Žilina' -->

Will match, and element will have this text, which is not equals to 'Box Sport Žilina'. Check contains in the assertion as well

assert 'Box Sport Žilina' in element
Guy
  • 46,488
  • 10
  • 44
  • 88
  • so i need some other method instead contains? – Luke Teensie Jan 22 '20 at 10:24
  • @LukeTeensie Contains is fine, but if you want to assert exact match you should check it's really an exact match, without blank spaces or unicode characters. – Guy Jan 22 '20 at 10:26
  • @LukeTeensie Because `"box"` is not equal to `"Box Sport Žilina"` either. – Guy Jan 22 '20 at 10:50
  • @LukeTeensie if this is only white spaces issue you can do `assert element.strip() == "Box Sport Žilina"` – Guy Jan 22 '20 at 11:18
0

Try with input.get_attribute('value')

Refer URL: Get value of an input box using Selenium (Python)

autom99
  • 88
  • 3
  • I tried but it do not works. Value means the text I write into field? First thing that I have some dropdown list and pre-defined text in code, it works with assert for only string without spaces. Second thing is when I imput some text I write myself. It is not saved to code or its not visible "there"... – Luke Teensie Jan 22 '20 at 12:21