Selenium send_keys – method sends xpath( Python abnormal behavior )
Question:
I am working on a Tinder project and for that I would like to log in with google. I managed to hide from and I could log in with success, however when I use the send_keys method to send my email, it sends the xpath of the email input element along side with the email( also it sends the wait method which is at the end of my code). it is a weird behavior, do you know how to solve it?
CODE:
if __name__ == '__main__':
driver = uc.Chrome()
driver.get('https://tinder.com/')
wait()
current_driver = driver.current_window_handle
wait()
login = driver.find_element(by=By.CLASS_NAME, value='button')
login.click()
wait()
wait()
accept_cookeis = driver.find_element(by=By.XPATH, value='/html/body/div[1]/div/div[2]/div/div/div[1]/button')
wait()
accept_cookeis.click()
wait()
main_page = driver.current_window_handle
wait()
google_login = driver.find_element(by=By.XPATH, value='/html/body/div[2]/div/div/div[1]/div/div[3]/span/div[1]/div/button/span[2]')
wait()
google_login.click()
wait()
my_windows = driver.window_handles
wait()
for window in my_windows:
if window != main_page:
driver.switch_to.window(window)
wait()
email_input = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[1]/input')
wait()
email_input.send_keys(YOUR_EMAIL)
time.sleep(1000)
Answers:
Add
import time
at beginning of your code.
so that,
time.sleep(1000)
works as expected.
So I used a JavaScript snippet and it solved the problem, however I still don’t know what causes this.
Example:
driver.execute_script('return document.getElementsByName("username")[0].value')
I am working on a Tinder project and for that I would like to log in with google. I managed to hide from and I could log in with success, however when I use the send_keys method to send my email, it sends the xpath of the email input element along side with the email( also it sends the wait method which is at the end of my code). it is a weird behavior, do you know how to solve it?
CODE:
if __name__ == '__main__':
driver = uc.Chrome()
driver.get('https://tinder.com/')
wait()
current_driver = driver.current_window_handle
wait()
login = driver.find_element(by=By.CLASS_NAME, value='button')
login.click()
wait()
wait()
accept_cookeis = driver.find_element(by=By.XPATH, value='/html/body/div[1]/div/div[2]/div/div/div[1]/button')
wait()
accept_cookeis.click()
wait()
main_page = driver.current_window_handle
wait()
google_login = driver.find_element(by=By.XPATH, value='/html/body/div[2]/div/div/div[1]/div/div[3]/span/div[1]/div/button/span[2]')
wait()
google_login.click()
wait()
my_windows = driver.window_handles
wait()
for window in my_windows:
if window != main_page:
driver.switch_to.window(window)
wait()
email_input = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[1]/input')
wait()
email_input.send_keys(YOUR_EMAIL)
time.sleep(1000)
Add
import time
at beginning of your code.
so that,
time.sleep(1000)
works as expected.
So I used a JavaScript snippet and it solved the problem, however I still don’t know what causes this.
Example:
driver.execute_script('return document.getElementsByName("username")[0].value')