1

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)
2
  • Store the actual string of sctitle.text as an object instead and use that for elem.send_keys. e.g. sctext = sctitle.text; ... elem.send_keys(sctext) Commented Apr 2, 2020 at 15:30
  • i already try this, but nothing happens and the driver stopped. Commented Apr 2, 2020 at 15:34

1 Answer 1

3

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')

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

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.