python - Finding element by a variable -



python - Finding element by a variable -

i'm trying select element dropdown list. element defined value, date. example, let's date i'm trying select today. element's value "2014/10/06"

i have defined variable "oracledate" links field "2014/10/06". know defining correctly because when print(oracledate) appears 2014/10/06.

however, next code not work:

browser.find_element_by_xpath("//option[contains(@value, oracledate)]").click()

when hardcode, works properly:

browser.find_element_by_xpath("//option[contains(@value, '2014/10/04')]").click()

why isn't working when seek find element using variable?

use str.format:

>>> oracledata = '2014/10/04' >>> "//option[contains(@value, '{}')]".format(oracledata) "//option[contains(@value, '2014/10/04')]"

or % operator:

>>> "//option[contains(@value, '%s')]" % oracledata "//option[contains(@value, '2014/10/04')]"

python string selenium

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -