selenium 4.14.0 和 Mozilla 119.0 和 GeckoDriver-v0.33.0

selenium 4.14.0 and mozilla 119.0 and GeckoDriver-v0.33.0

提问人: 提问时间:11/3/2023 更新时间:11/3/2023 访问量:444

问:

我正在使用 selenium 4.14.0 和 mozilla 119.0 以及 GeckoDriver-v0.33.0。

1)

from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
def instagram_login(username, password):
options = Options()
options.headless = True
service = Service('C:\geckodriver\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=options)
driver.get('https://www.instagram.com/')
time.sleep(2)
username_input = driver.find_element(By.NAME, 'username')
username_input.send_keys(username)
username_input.send_keys(Keys.ENTER)
time.sleep(2)
password_input = driver.find_element(By.NAME, 'password')
password_input.send_keys(password)
password_input.send_keys(Keys.ENTER)
time.sleep(2)
driver.quit()
username = ''
password = ''
instagram_login(username, password)

2)

from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Firefox()
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
title = driver.title
driver.implicitly_wait(0.5)
text_box = driver.find_element(by=By.NAME, value="my-text")
submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button")
text_box.send_keys("Selenium")
submit_button.click()
message = driver.find_element(by=By.ID, value="message")
text = message.text
driver.quit()

我需要我编写的 1-ci 代码,但我使用 2 代码,因为它不起作用。我需要用第一个代码替换第二个代码。我该怎么做?

python selenium-webdriver firefox geckodriver selenium4

评论


答: 暂无答案