0

I am automating shopping site, where at last I want to print the total bill. I have tried the following code but error shown that no such attribute is known. Code here is here:

price = driver.find_element_by_xpath('//*[@id="price-overview"]/div[1]/div/div/div[1]/div[2]/dl/dd')
                                
                                    
 price_value = price.getAttribute("US $");
 print("The total price is: "+ str(price_value));
`  [![highlighted in image too][1]][1]

image is here

5
  • 1
    "but didn't work" is not a helpful description of what happened. Commented May 12, 2021 at 12:40
  • error shown that no such attribute is known Commented May 12, 2021 at 12:49
  • Can you share the url or html Commented May 12, 2021 at 12:50
  • So why would you think that an HTML element would have an attribute with the name "US $"? As another user said, post a snippet of the HTML tags. Commented May 12, 2021 at 13:14
  • get_attribute() not getAttribute Commented May 13, 2021 at 2:24

2 Answers 2

1

Instead of price.getAttribute("US $"); you should use price.getText() since it's just a text there.
Also, there no need to put ; at the end of the commands. It's Python, not Java :)

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

Comments

0

To get an attribute in Python, use get_attribute() not getAttribute. If there is really such attribute, it should solve your question.

Another approach you can try: Find the correct locator and add to it .get_attribute("innerHTML").

Such locator does not seem to be correct: //*[@id="price-overview"]/div[1]/div/div/div[1]/div[2]/dl/dd. It is not stable, has high probability to be changed.

Use driver.find_element_by_xpath('short xpath').text to the text from an element.

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.