0

I was trying selenium recently and I need to find data on a first webpage. After that I need to go to an 2nd webpage and paste the data find on the 1st webpage.

But I can't transfer data from the first webpage, its look like the data in the variable getNumber is lost in transit.

getNumber = driver.find_element(By.XPATH, '/html/body/section/div/div[2]/div[2]/div[2]/div[2]/div/div[4]/span/center/button')
print("Numéro de téléphone : ", getNumber.text) #THIS IS WORKING GREAT

driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
driver.get("https://www.my2ndwebsite.com") #THIS IS WORKING GREAT
nmb = driver.find_element(By.XPATH, '//*[@id="useridInput"]')
nmb.send_keys(getNumber) #THIS IS NOT WORKING GREAT

If I put text like "test" instead my var getNumber, its perfectly working so the problem is my variable.

Can you help me please?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

You've put web-element object to getNumber variable.

You're able to interact it while the current page is opened and the element is present on the page.

Here you switched to the new page, so the driver context has been changed, and it not able to find getNumber element anymore..

I believe you have to put the element text, not the element itself to getNumber.

getNumber = driver.find_element(By.XPATH, '/html/body/section/div/div[2]/div[2]/div[2]/div[2]/div/div[4]/span/center/button').text
Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14
0

getNumber is the WebElement where as

getNumber.text

would give you the desired text.


Solution

Instead of:

nmb.send_keys(getNumber)

you need to:

nmb.send_keys(getNumber.text)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352