通过 paypal 登录导航时,Selenium webdriver 停止且没有错误消息

Selenium webdriver stops with no error-message when navigating through paypal login

我正在尝试登录 paypal.com 并自动付款。

程序成功加载了登录页面(https://www.paypal.com/us/signin)并输入了电子邮件,但是当我单击下一步按钮时,网络驱动程序意外关闭而没有生成错误消息。

有没有人遇到过这个问题?难道是因为下一个按钮是伪装的验证码,以防止机器人登录?

我已经尝试使用 time.sleep(3) 来给页面加载时间。我看不到代码有任何其他问题。

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys


def paypal_pay(): # pass in user address

    driver = webdriver.Chrome()

    timeout = 20
    paypal = "https://www.paypal.com/us/signin"

    driver.get(paypal)
    email = "emailstuff@gmail.com"
    emailElement = driver.find_element_by_id('email')
    print(emailElement)
    emailElement.send_keys(email)
    time.sleep(3)
    nextElement = driver.find_element_by_id('btnNext').click()


def main():
    paypal_pay()
main()

当我 运行 你的代码点击下一步按钮后 Chrome 浏览器崩溃并且在控制台中我可以看到以下错误。

<selenium.webdriver.remote.webelement.WebElement (session="577ff51b46a27eefeda43ccd320db48b", element="0.571535141628553-1")>

这意味着您需要开始 RemoteWebDriver 而不是 ChromeDriver

第 1 步:从以下 link

下载 Selenium Standalone Server
https://www.seleniumhq.org/download/

第 2 步:以管理员身份打开命令提示符进入下载路径并键入以下命令并按回车键

java -jar selenium-server-standalone-3.141.59.jar

第 3 步:要验证集线器是 运行ning,请打开浏览器并输入下面的 url.Default 集线器端口是 4444

http://localhost:4444/grid/console

第 4 步:使用以下 code.If 你正确地按照上面的步骤操作它应该可以完美地运行下面的代码。

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

def paypal_pay(): # pass in user address


    desired_caps = DesiredCapabilities.CHROME
    grid_url = "http://localhost:4444/wd/hub"
    driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor=grid_url)
    paypal = "https://www.paypal.com/us/signin"
    driver.get(paypal)
    email = "emailstuff@gmail.com"
    emailElement = driver.find_element_by_id('email')
    print(emailElement)
    emailElement.send_keys(email)
    nextElement = driver.find_element_by_id('btnNext')
    nextElement.click()


def main():
    paypal_pay()
main()

如果这对 you.Good 运气有用,请告诉我。

您的代码工作正常,但您实现的方式导致了问题,我的意思是您正在使用 main() 方法,它会做的是,一旦调用并执行此方法,它将在最后关闭所有连接。因此,您的浏览器也没有任何错误地关闭的原因是因为您的代码在此之前工作正常:

试试下面没有 main 方法的修改代码,它完全可以正常工作:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("chromedriver.exe");

paypal = "https://www.paypal.com/us/signin"

driver.get(paypal)
email = "hello@gmail.com"
emailElement = driver.find_element_by_id('email')
print(emailElement)
emailElement.send_keys(email)
time.sleep(3)
nextElement = driver.find_element_by_id('btnNext').click()

print("=> Done...")

有关 main() 的更多信息,请参阅 this link

希望对您有所帮助...