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")
4
  • That span does not have a value attribute. So you'd be interested in getting the HTML of the span Commented Oct 18, 2017 at 13:42
  • 1
    Possible duplicate of How to get text with selenium web driver in python Commented Oct 18, 2017 at 13:53
  • driver.get_element_by_css_selector('#nav-search form span.hlb-price').text Commented Oct 18, 2017 at 13:58
  • @Andersson - nope it is other issue Commented Oct 18, 2017 at 14:19

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What Xpath are you using
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;

Comments

0

This one worked for me:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.