The_Diver
The_Diver

Reputation: 1915

How to copy a text and store it into a variable using Selenium? Python

I want to copy a text from a website and store it into a variable so I can add it to a dictionary later. I wanted to know how do I accomplish it?

Here is my source code:

from selenium import webdriver

f = webdriver.Firefox()

f.get("http://hi.com")

g = f.find_element_by_tag_name('h1').getText()

print g 

Upvotes: 1

Views: 18029

Answers (1)

Vishal Jagtap
Vishal Jagtap

Reputation: 896

What type of text you need to copy from web page?

You need to locate webelement of text you need to capture and simply use getText() on it.

String text = driver.findElement(By.id("some id")).getText();

Upvotes: 1

Related Questions