这个错误通常是因为selenium版本太低,缺少必要的包或模块,或者你正在使用的元素没有below属性。你可以尝试升级你的selenium版本,或使用必要的包或模块。如果你确保使用的元素具有below属性,请确保你的代码正确使用它。以下是一些可能导致此错误的示例代码:
#示例1:
elem = driver.find_element_by_class_name("my-class")
elem.below # 错误
#示例2:
elem = driver.find_element_by_xpath("//div[@class='my-class']")
elem.below() # 错误
#示例3:
from selenium.webdriver.common.action_chains import ActionChains
elem = driver.find_element_by_class_name("my-class")
action = ActionChains(driver)
action.move_to_element(elem).below() # 错误
解决这个问题的方法是使用与元素相关的正确方法。以下是相应的更正代码:
#示例1:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
elem = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "my-class")))
elem.location_once_scrolled_into_view
# 或者
from selenium.webdriver.common.keys import Keys
elem.send_keys(Keys.DOWN) # 或者任何其他向下滚动元素的方法
#示例2:
elem = driver.find_element_by_xpath("//div[@class='my-class']")
elem.location_once_scrolled_into_view
# 或者
from selenium.webdriver.common.keys import Keys
elem.send_keys(Keys.DOWN) # 或者任何其他向下滚动元素的方法
#示例3:
from selenium.webdriver.common.action_chains import ActionChains
elem = driver.find_element_by_class_name("my-class")
action = ActionChains(driver)
action.move_to_element(elem).click().perform()
上一篇:AttributeError:'WebDriver'objecthasnoattribute'findElement'”
下一篇:AttributeError:'xml.etree.ElementTree.Element'objecthasnoattribute'_children'--notadupe