Manipulate xpath using variables

后端 未结 2 1589
庸人自扰
庸人自扰 2021-01-24 13:27

So I have the code where the user inputs a color variable and the string for it is called color. Example link - https://www.supremenewyork.com/shop/jackets/k56l3oteu/hjylineo1 .

2条回答
  •  一个人的身影
    2021-01-24 14:09

    You can use string formats below, but there is error in your xpath - missing ] at the end:

    driver.find_element_by_xpath("//a[@data-style-name='{}']".format(color.get()))
    driver.find_element_by_xpath("//a[@data-style-name='{0}']".format(color.get()))
    driver.find_element_by_xpath("//a[@data-style-name='%s']" % color.get())
    

提交回复
热议问题