Selenium send_keys - 方法发送xpath(Python异常行为)
我正在开发一个 Tinder 项目,为此我想使用 google 登录。我设法隐藏并且可以成功登录,但是当我使用 send_keys 方法发送电子邮件时,它会随电子邮件一起发送电子邮件输入元素的 xpath(它还会发送位于我的代码结束)。这是一种奇怪的行为,你知道如何解决吗?
代码:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我使用了一个 JavaScript 片段,它解决了问题,但我仍然不知道是什么原因导致的。
例子:
So I used a JavaScript snippet and it solved the problem, however I still don't know what causes this.
Example:
添加
在代码的开头。
这样,
就可以按预期工作。
Add
at beginning of your code.
so that,
works as expected.