Cách đăng nhập với selenium webdriver

Sep 11 2020

Xin chào Tôi đang cố gắng đăng nhập tự động bằng trình duyệt web vào trang web này: https://www.oddsportal.com/login/

Đây là kịch bản của tôi:

#!/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()

Tôi gặp sự cố với dòng mã cuối cùng. Trang web mở ra sau đó tên người dùng và mật khẩu bị tính phí nhưng sau đó tôi không đăng nhập.

Trả lời

ahmedaao Sep 12 2020 at 19:06

Tôi tìm thấy giải pháp:

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