0

I have an element:

<span class="a-color-price hlb-price a-inline-block a-text-bold">$399.98</span>

and I want to extract the price value in dollars which appears in the element’s text.

I have tried:

driver.get_element_by_xpath('//*[@id="nav-search"]/form/div[2]/div/input').get_attribute("value")
Jerry Stratton
  • 3,057
  • 1
  • 21
  • 27
Erez Naim
  • 1
  • 1
  • 6

3 Answers3

1

What about:

SpanVariable = driver.get_element_by_xpath('Put Xpath Here')

SpanVariableValue = SpanVariable.text
print SpanVariableValue  # $399.98

You need to grab the text of the element you are looking at. Place the element you located in a variable, and then you can call selenium functions to it. In this case, .text grabs the text of your span element for you.

Goralight
  • 1,997
  • 5
  • 26
  • 36
0

I'm not sure what you're doing wrong, it should be pretty simple. I use C# but based on what you've given I'd try this. And if this doesn't work, use a upper case 't' for the ending '.Text;' part of the call.

my_spanText = driver.get_element_by_xpath("//span[@class='a-color-price hlb-price a-inline-block a-text-bold']").text;
JOberloh
  • 886
  • 2
  • 8
  • 18
0

This one worked for me:

element=driver.find_element_by_xpath('//*[@id="hlb-subcart"]/div[1]/span/span[2]').text

Erez Naim
  • 1
  • 1
  • 6