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?
enter image description here

Asked By: DiegoEwin

||

Answers:

Your selector

"//span[@class='item-price.js-variant-price'"

is incorrect:

  1. You missed closing square bracket
  2. 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

Answered By: JaSON
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.