1

How can I copy text from somewhere in the website? I have line with only text and i I don't know how to copy it by using xpath and paste it later in other xpath command.(I know how to find it)I want to get email from 10 minutes email and paste it later in something else. Below is the code I have tried so far.

driver.get("10minutemail.pl/")
email_elem = driver.find_element_by_xpath("/html/body/div[1]/div[3]/div[1]/div[1]/div[1]/form[1]/div[1]/input[1]"
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
szymond45
  • 87
  • 1
  • 1
  • 8

2 Answers2

1

U need to find your element, get element text(email) and assign this text to some global string variable, so later u can use this text where you want. I know u using python, but here is example with Java so you can see the logic should be similar.

public String getEmailText = driver.findElement("your xpath to email").getText();
once u get it u can use it somewhere else, even paste it as a text later.
driver.findElement("new x path where u want to paste saved text").sendKey(getEmailText);
IPolnik
  • 619
  • 5
  • 13
  • i get error: TypeError: 'str' object is not callable with code: email2_elem = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/input[1]").text() – szymond45 Apr 03 '19 at 06:26
  • https://stackoverflow.com/questions/6039605/typeerror-str-object-is-not-callable-python. Probably need to add or remove 'global' before string. Also try to read this article. I can help u only with C# or Java. – IPolnik Apr 03 '19 at 13:39
0

Welcome to SO. If you are trying to read the text from the UI and then use that as part of your xpath - yes it's possible check the below example.

driver.get("httsp://google.com")
textToSearch = driver.find_element_by_css_selector("#hptl a:first-child").text
driver.find_element_by_xpath("//a[.='" + textToSearch + "']").click()
supputuri
  • 13,644
  • 2
  • 21
  • 39