A
A
altezza0722018-03-13 15:46:28
Python
altezza072, 2018-03-13 15:46:28

Variable in xpath locator?

Good afternoon, there is such a serial_number variable that takes on a certain value
if you search for an element in this way:

find_serial_number = browser.find_element_by_xpath(".//*[contains(text(),'sn-12345']")

then everything works, but if you use a variable, then such an element is not found, I tried it in two ways
find_serial_number = browser.find_element_by_xpath(".//*[contains(text(),'sn-{0}'][' + serial_number']"

find_serial_number = browser.find_element_by_xpath(".//*[contains(text(),'sn-{0}'].format(serial_number)")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Palych, 2018-03-13
@xzKakoyLogin

find_serial_number = browser.find_element_by_xpath(".//*[contains(text(),'"+serial_number+"')]")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question