我是非常新的编程,目前正在四处乱搞,试图制造一个机器人,将添加项目到我的购物车我。我正在使用python和selenium模块。我遇到的问题是如何让程序找到一个使用src或href代码的项目。
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(())
)
element.click()
这是我正在使用的代码,我不知道如何在括号中找到src或href。我想知道哪个更容易使用,以及如何在我的代码中使用它。任何建议/批评都可以帮助我,因为我还在学习巨蟒。谢谢。
发布于 2020-12-22 01:26:02
因此,你的问题如下:
如何使用src或href代码查找项
让我们以一个代码片段为例。
这是来自https://www.google.com/的起始页面。如果您希望通过专门查找href url来查找具有上述anchor
属性的href
元素,则需要使用以下方法进行搜索:
driver.find_element_by_xpath('//a[@href="https://mail.google.com/mail/?tab=rm&ogb"]')
您的代码片段也是如此:
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, ('//a[@href="https://mail.google.com/mail/?tab=rm&ogb"]'))))
element.click()
进口模块:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
https://stackoverflow.com/questions/65401718
复制相似问题