I'm using Python and Selenium Webdriver.
I have the following code which works as expected:
driver.find_element_by_xpath('//p[text()="text"]/../following-sibling::td/div/div/table/tbody/tr/td/a[@class ="class_name"]')
I would like to change the above "text" to a variable, similar to the below:
driver.find_element_by_xpath('//p[text()="%s"] % variable_name/../following-sibling::td/div/div/table/tbody/tr/td/a[@class ="class_name"]')
This doesn't work as it isn't a valid XPath express. Can anyone help with the correct coding please?
Edit:
Also, if there is a way to search for text in the follow-sibling that would also be useful. Something similar to:
driver.find_element_by_xpath('//p[text()="%s"] % variable_name/../following-sibling:[div@text()= "text"]')
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…