Using a variable in xpath in Python Selenium -
i've been having trouble figuring out how variable work selenium. post seems have helped (variable not working inside parenthesis) still can't work.
when used actual value works. in case al-alabama. created variable called state can call in function. have 13 states run through.
driver.find_element_by_xpath("//option[@value='al-alabama']").click() this 1 uses state variable , in looking @ error message shows variable value al-alabama. seems it's referencing correct value in web page. not sure i'm missing or why it's not working. guidance appreciated.
driver.find_element_by_xpath('//option[@value=' + state + ']').click() selenium.common.exceptions.nosuchelementexception: message: no such element: unable locate element: {"method":"xpath","selector":"//option[@value=al-alabama]"}
the single quotes around value not present how coded it. try:
driver.find_element_by_xpath("//option[@value='" + state + "']").click()
Comments
Post a Comment