简体   繁体   English

我如何单击 selenium python 中列表的特定类别元素

[英]How can i click specific category element of list in selenium python

from selenium import webdriver

import time

from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Chrome("C:/Users/ysatish/PycharmProjects/all rules/driver/chromedriver.exe")

driver.maximize_window()

driver.implicitly_wait(10)

driver.get("https://www.myntra.com/men-tshirts")

chali = driver.find_elements_by_xpath('//li//a[1]//div[2]//div[1]//span')

dak = driver.find_elements_by_xpath('//li//a[1]//div[2]//div[1]//span[1]')

sub = len(chali)

da = len(dak)

print(da)
print(sub
Updated solution:
driver.get('https://www.myntra.com/men-tshirts')
wait = WebDriverWait(driver, 10)
chali = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//li[*]//a[1]//div[2]//div[1]//span[1]")))
print(len(chali))
for element in chali:
    print element.text
    element.click()

dak = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//li//a[1]//div[2]//div[1]//span")))
print(len(dak))
for element0 in dak:
    print element0.text
element0.click()

Note: please add below imports to your solution注意:请将以下导入添加到您的解决方案中

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

Updated Solution:更新的解决方案:

//li[*]//a[1]//div[2]//div[1]//span[not(@class='product-strike')][not(@class='product-discountedPrice')][not(@class='product-discountPercentage')][last()]//span[1]

and

//li[*]//a[1]//div[2]//div[1]//span

Output: Output:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 和 selenium 为网络爬虫找到对列表中特定元素的引用,该元素的长度定期变化 - How can I find reference to a specific element in a list that changes in length regularly using python and selenium for a webscraper 如何使用硒和python单击网页上的元素 - How can i click the element on webpage using selenium with python 找到后如何单击 Python Selenium 中的元素? - How can I click an element in Python Selenium after finding it? 如何在 python 中使用 selenium 在不和谐页面上单击此元素? - how can i click this element on the discord page with selenium in python? 如何在python中使用selenium选择具有特定`title`的元素 - How can I select an element with a specific `title` using selenium in python 如何在 python 中的 selenium 中获取此特定元素 - How can I get this SPECIFIC element in selenium in python 无法使用 selenium/python 单击特定元素(尝试了 iframe 以及我知道或在这里找到的所有方法) - Can't click on a specific element using selenium/python (tried iframe and all the methods that I know or found here) 如何在python selenium中点击web元素列表中的第二个元素? - How to click on second element from list of web element in python selenium? 如何从python的此列表中选取特定元素? - how can i take a specific element from this list in python? Python Selenium 如何单击此按钮 - Python Selenium How can I click this button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM