目录
-
- 方法一: selenium 方法
- 方法二:js 方法
方法一: selenium 方法
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_experimental_option('useAutomationExtension', False)
browser = webdriver.Chrome(executable_path=r"./chromedriver_win32/chromedriver.exe",options=chrome_options)
browser.maximize_window()
browser.get("https://de01-intland03.corp.int/cb/login.spr")
userElement = browser.find_element_by_xpath(".//input[@id ='user']")
userElement.send_keys('账号')
passElement = browser.find_element_by_xpath(".//input[@id ='password']")
passElement.send_keys('密码')
click_login = browser.find_element_by_xpath(".//input[@class ='login_button']")
click_login.click()
方法二:js 方法
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_experimental_option('useAutomationExtension', False)
browser = webdriver.Chrome(executable_path=r"./chromedriver_win32/chromedriver.exe",options=chrome_options)
browser.maximize_window()
browser.get("https://de01-intland03.corp.int/cb/login.spr")
js1 = 'document.getElementById("user").value="账号";'
browser.execute_script(js1)
js2 = 'document.getElementById("password").value="密码";'
browser.execute_script(js2)
js3 = 'document.querySelector("input.login_button").click();'
browser.execute_script(js3)