我正在尝试执行此代码并显示' NoSuchElementException'这个错误。 所以有人可以帮我吗?
代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver= webdriver.Chrome()
page=driver.get("http://www.awgp.org")
banner_tell=driver.find_element_by_Link_text('Tell Me More')
banner_tell.click()
答案 0 :(得分:1)
我认为您需要做的就是以大写字母提供链接文本,但此链接是动态的,因为横幅会自动滑动到下一个。
您应该提供另一个定位器,以便完全单击要单击的定位器。否则,如果横幅已更改,您可能会获得ElementNotVisibleException
。
banner_tell=driver.find_element_by_link_text('TELL ME MORE')
答案 1 :(得分:0)
尝试使用xpath
banner_tell= driver.find_element_by_xpath("//*[contains(text(),'TELL ME MORE')]")
答案 2 :(得分:0)
似乎你几乎要靠近function()
应该是:
find_element_by_link_text()
要点击按钮,文字为 TELL ME MORE ,您必须使用WebDriverWait条expected_conditions引导element_to_be_clickable
,如下所示:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "TELL ME MORE"))).click()