Extracting price in span using selenium python?
Question:
I’m trying to obtain the price text in the following html code:
<span class="item-price js-variant-price" content="79.95" itemprop="price">79,95 TL</span>
Using the code, i have this
prices2=driver.find_element(By.XPATH, "//span[@class='item-price.js-variant-price'")
but so far it can’t get the "79.96" value, what am I doing wrong?
Answers:
Your selector
"//span[@class='item-price.js-variant-price'"
is incorrect:
- You missed closing square bracket
- In XPath predicate you don’t need to separate class names with dot
Correct XPath would be
"//span[@class='item-price js-variant-price']"
Also note that Price value might come from XHR so you might need to implement Wait to get it
I’m trying to obtain the price text in the following html code:
<span class="item-price js-variant-price" content="79.95" itemprop="price">79,95 TL</span>
Using the code, i have this
prices2=driver.find_element(By.XPATH, "//span[@class='item-price.js-variant-price'")
but so far it can’t get the "79.96" value, what am I doing wrong?
Your selector
"//span[@class='item-price.js-variant-price'"
is incorrect:
- You missed closing square bracket
- In XPath predicate you don’t need to separate class names with dot
Correct XPath would be
"//span[@class='item-price js-variant-price']"
Also note that Price value might come from XHR so you might need to implement Wait to get it