Home > front end >  How to use multiple variables for xpath?
How to use multiple variables for xpath?

Time:01-21

I'm trying to find element by xpath that contains multiple variables and click on it.

I tried using :

oddsnumber = "1.18"
oddstype = "Barcelona"
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@span='"  oddstype  "' and @span='"  oddsnumber  "']"))).click()

With only one variable it works, but I need to use multiple in order for script to click on right element.

This is the element it should click on

<div ><span >Barcelona</span><span >1.18</span></div>
     <span >Barcelona</span>
     <span >1.18</span>

Tried to make a script that clicks on element by xpath that matches to multiple variables

CodePudding user response:

You can use this xpath, which targets a div element having two span children with the requested attributes

f"//div[child::span[text()='{oddsnumber}'] and span[text()='{oddstype}']]"
  • Related