Omar Yacop
Omar Yacop

Reputation: 73

How to copy HTML content with Selenium

I am trying to send an email, which is done with HTML and CSS, with Selenium, it appears that it can't get the page itself, only the text, or the code, so is there a way to copy the page.

Tried:

  1. Sending Keys, (Keys.CONTROL + 'A').... (Keys.CONTROL + 'C') and assigning it to a var but didn't get what I want.

  2. Constructing a field in the beginning and manually copy the content and paste it in the field, then getting its value, but same thing, it only gets the text.

Upvotes: 0

Views: 1645

Answers (2)

Rafael C.
Rafael C.

Reputation: 2335

Basically you need to get the outerHTML attribute from the target element.

Let's say you want to store all the HTML content (tags and text) from the contentEmail ID:

<div id="contentEmail">
   <span>
     My content email here!
     <br>
   </span>
</div>

To do this, you need this:

html_content = self.find_element(By.ID, "contentEmail").get_attribute("outerHTML")
print(html_content)

Upvotes: 2

Omar Yacop
Omar Yacop

Reputation: 73

I found it,

the Sending Keys,

(Keys.CONTROL + 'A')

(Keys.CONTROL + 'C') worked but I just needed to send (Keys.CONTROL + 'V') Not assigning it to a var

Upvotes: 0

Related Questions