How to use multiple variables for xpath?
Question:
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 class="gl-Participant gl-Participant_General gl-Market_General-cn3 "><span class="gl-Participant_Name">Barcelona</span><span class="gl-Participant_Odds">1.18</span></div>
<span class="gl-Participant_Name">Barcelona</span>
<span class="gl-Participant_Odds">1.18</span>
Tried to make a script that clicks on element by xpath that matches to multiple variables
Answers:
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}']]"
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 class="gl-Participant gl-Participant_General gl-Market_General-cn3 "><span class="gl-Participant_Name">Barcelona</span><span class="gl-Participant_Odds">1.18</span></div>
<span class="gl-Participant_Name">Barcelona</span>
<span class="gl-Participant_Odds">1.18</span>
Tried to make a script that clicks on element by xpath that matches to multiple variables
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}']]"