我试图使用python在Selenium webdriver中使用click命令.但我收到以下错误.有人能帮我吗?
Traceback (most recent call last):
File "C:\Users\vikram\workspace\LDC\test.py", line 13, in <module>
driver.find_elements_by_link_text("MISCQA Misc Tests").click()
AttributeError: 'list' object has no attribute 'click'
Run Code Online (Sandbox Code Playgroud)
这是我的计划
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
import config
url = config.config.get('url')
driver = webdriver.Ie()
driver.get(url)
driver.find_elements_by_link_text("MISCQA Misc Tests").click()
driver.close()
Run Code Online (Sandbox Code Playgroud)
我想我错过了一些东西.请建议我
我正在尝试使用 Python 和 Selenium 来抓取网页上的多个链接。我正在使用find_elements_by_xpath
并且我能够找到一个元素列表,但是我无法更改返回到实际href
链接的列表。我知道find_element_by_xpath
有效,但这仅适用于一种元素。
这是我的代码:
path_to_chromedriver = 'path to chromedriver location'
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
browser.get("file:///path to html file")
all_trails = []
#finds all elements with the class 'text-truncate trail-name' then
#retrieve the a element
#this seems to be just giving us the element location but not the
#actual location
find_href = browser.find_elements_by_xpath('//div[@class="text truncate trail-name"]/a[1]')
all_trails.append(find_href)
print all_trails
Run Code Online (Sandbox Code Playgroud)
此代码返回:
<selenium.webdriver.remote.webelement.WebElement
(session="dd178d79c66b747696c5d3750ea8cb17",
element="0.5700549730549636-1663")>,
<selenium.webdriver.remote.webelement.WebElement
(session="dd178d79c66b747696c5d3750ea8cb17",
element="0.5700549730549636-1664")>,
Run Code Online (Sandbox Code Playgroud)
我期待all_trails
阵列是像链接列表:www.google.com, www.yahoo.com, www.bing.com
。 …
python selenium web-scraping selenium-chromedriver selenium-webdriver