写一个selenium的代码要求点击加入购物车弹出界面点击界面上的确定按钮依次点击
以下是一个用Python编写的Selenium代码,实现了点击加入购物车按钮,弹出界面后点击确定按钮的功能:
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
# 创建Chrome浏览器实例
driver = webdriver.Chrome()
# 打开网页
driver.get("https://www.example.com")
# 点击加入购物车按钮
add_to_cart_button = driver.find_element(By.XPATH, "//button[contains(text(), '加入购物车')]")
add_to_cart_button.click()
# 等待弹出界面出现
popup = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "popup")))
# 点击确定按钮
confirm_button = popup.find_element(By.XPATH, "//button[contains(text(), '确定')]")
confirm_button.click()
# 关闭浏览器
driver.quit()
请将 https://www.example.com 替换为你要操作的具体网页地址
原文地址: https://www.cveoy.top/t/topic/hZSF 著作权归作者所有。请勿转载和采集!