如何使用 Selenium 和 Python 从产品列表中单击多个 'Add to cart' 按钮?
How to click multiple 'Add to cart' button from product list using Selenium and Python?
我可以添加单个和所有可用项目,但不确定如何添加多个项目
enter image description here
enter image description here
使用方法 items.remove()、items.pop()、del items[].
从项目中删除不必要的元素
你的问题不清楚,请下次提供更多细节,请不要分享带有屏幕截图的代码......
无论如何,
点击所有按钮:
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
driver = webdriver.Chrome()
driver.get("https://rahulshettyacademy.com/seleniumPractise/#/")
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "[class='product-action']")))
for i in driver.find_elements(by=By.CSS_SELECTOR, value="[class='product-action']"):
i.click()
仅单击前两个按钮(同样,不确定您真正想要的是什么):
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
driver = webdriver.Chrome()
driver.get("https://rahulshettyacademy.com/seleniumPractise/#/")
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "[class='product-action']")))
for i in driver.find_elements(by=By.CSS_SELECTOR, value="[class='product-action']")[0:2]:
i.click()
我可以添加单个和所有可用项目,但不确定如何添加多个项目
enter image description here
enter image description here
使用方法 items.remove()、items.pop()、del items[].
从项目中删除不必要的元素你的问题不清楚,请下次提供更多细节,请不要分享带有屏幕截图的代码......
无论如何,
点击所有按钮:
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
driver = webdriver.Chrome()
driver.get("https://rahulshettyacademy.com/seleniumPractise/#/")
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "[class='product-action']")))
for i in driver.find_elements(by=By.CSS_SELECTOR, value="[class='product-action']"):
i.click()
仅单击前两个按钮(同样,不确定您真正想要的是什么):
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
driver = webdriver.Chrome()
driver.get("https://rahulshettyacademy.com/seleniumPractise/#/")
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "[class='product-action']")))
for i in driver.find_elements(by=By.CSS_SELECTOR, value="[class='product-action']")[0:2]:
i.click()