0

I would like to get the text inside this specific element here

<div class="comment-text-inner display-inline" data-clipboard-text="free apex coins">free apex coins</div>

How do I get the text from "data-clipboard-text" using python and selenium?

I've tried

comment = driver.find_element_by_xpath("""/html/body/div[3]/div/div[2]/div[2]/div/div/div/div[4]/div[2]/div/div[1]""").text

With no luck

4
  • 1
    That xpath depends on the entire document structure, which you haven't shown us, so we don't know why it isn't working. Commented Feb 24, 2019 at 17:46
  • Well, i get the same output if I use the classname "comment-text-inner" Commented Feb 24, 2019 at 17:48
  • What the comment variable consists of after this line is "loading". Which isn't anywhere in the element. Commented Feb 24, 2019 at 17:52
  • Possible duplicate of How to get attribute of element from Selenium? Commented Feb 24, 2019 at 18:18

1 Answer 1

3

I think you're looking for the method get_attribute().

Essentially, it'd be something like:

driver.find_element_by_xpath(<your xpath>).get_attribute("data-clipboard-text")

Please see this post as well.

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

2 Comments

He said he wanted the text. I don't think he wants the attribute value (though in this example they are the same).
His question specifically states How do I get the text from "data-clipboard-text" using python and selenium?

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.