How to copy an element text, In Selenium python

Jeremy Hunt :

my code is

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Firefox()
browser.get('example.com')


sctitle = browser.find_elements_by_tag_name('h1')
scp = browser.find_elements_by_xpath("//article[@id='the-post']//p[3]")[2].text

the goal is selenium select and copy the h1 title tag, Than in a new tab paste in in the form. i have problem with the copying and pasting it. when i want to paste it, Nothing happends. i use this command for paste:

browser.execute_script("window.open('');")
browser.switch_to.window(browser.window_handles[2])
browser.get('https://www.sitea.com')
elem = browser.find_element_by_class_name('TextArea__textArea')
elem.send_keys(sctitle.text)
Amit Verma :

Change the following to find only single element. find_elements returns a list so .text method doesn't work.

sctitle = browser.find_element_by_tag_name('h1')

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=390838&siteId=1