0
<li id="add-to-cart" class="">
    <input type="button" value="Add to Cart" class="primary" name="add-to-cart">
</li>

I want to print value

Output: Add to Cart

2
  • Update your question with code you've tried so far Commented Jan 16, 2017 at 10:06
  • You want to print value or name attribute? Commented Jan 16, 2017 at 10:08

2 Answers 2

1

Here my solution: first get elements inside < li> (Maybe there will be more than one):

elements = browser.find_elements_by_xpath("//li[@id='add-to-cart']//input")

for e in elements:
    print(e.get_attribute("name"))
Sign up to request clarification or add additional context in comments.

Comments

0

From Selenium docs:

  • find the button element using one of the find_element_by... methods on a driver (or on a parent WebElement)
  • read the name of the button or value of an input using .get_attribute(attribute_name)
  • read the text using property .text

1 Comment

Thanks for your answer It is giving error when I use .text It give output 0 when I print without .text

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.