如何使用Selenium WebDriver登录 [英] How to log in with selenium webdriver

查看:172
本文介绍了如何使用Selenium WebDriver登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用网络驱动程序自动登录到此网页: https://www.oddsportal.com/login/

Hello I am trying to log in automatically with webdriver to this webpage : https://www.oddsportal.com/login/

这是我的剧本:

#!/usr/bin/python3
# -*- coding: utf­-8 ­-*-

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from concurrent.futures import ThreadPoolExecutor

import pandas as pd

options = Options()
#options.headless = True
options.add_argument("window-size=1400,800")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("start-maximized")
options.add_argument("enable-automation")
options.add_argument("--disable-infobars")
options.add_argument("--disable-dev-shm-usage")

driver = webdriver.Chrome(options=options)

driver.get("https://www.oddsportal.com/login/")

driver.find_element_by_id("login-username1").send_keys("ahmedaao")
driver.find_element_by_id("login-password1").send_keys("password")
driver.find_element_by_name("login-submit").click()

我对最后一行代码有疑问.网页打开,然后向用户名和密码收费,但是我没有登录.

I have a problem with with the last line of code. The webpage open up then username and password are charged but then I am not logged in.

推荐答案

我找到了解决方法:

driver.find_element_by_xpath('//button[@type="submit"]').click()

这篇关于如何使用Selenium WebDriver登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆