i am using Selenium to scrape some stuff live, but i can't seem to search a WebElement even tho the docs say i can.
while True:
try:
member = self.pdriver.find_all("sv:member_profile")[index]
self.pdriver.info_log("Found a member")
except IndexError:
self.pdriver.info_log("No more members")
break
member.highlight(style = self.pdriver.get_config_value("highlight:style_on_assertion_success"))
profile = {}
profile["name"] = member.findElement("sv:member_name").get_attribute('innerHTML')
profile["image"] = member.findElement("sv:member_image").get_attribute('src')
profile["link"] = member.findElement("sv:member_link").get_attribute('href')
members.append(profile)
index += 1
This returns a single web element:
member = self.pdriver.find_all("sv:member_profile")[index]
which i need to search, according to the docs, this element would also have the findElement method, seems not to be the case tho?
AttributeError: 'WebElement' object has no attribute 'findElement'
As the error states, WebElement
object has no attribute findElement
. Depending on what are sv:member_name
, sv:member_image
and sv:member_link
, you need to choose which of the find_element_by_*
methods you need to use.
For instance, if sv:member_name
is a CSS selector:
profile["name"] = member.find_element_by_css_selector("sv:member_name").get_attribute('innerHTML')
Or, you may also use the find_element()
method directly supplying the By
value:
from selenium.webdriver.common.by import By
profile["name"] = member.find_element(By.CSS_SELECTOR, "sv:member_name").get_attribute('innerHTML')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.