在 Selenium 中滚动查找元素
Scroll for find element in Selenium
您好,我试图在 Selenium 中找到一个元素:
我发现:driver.execute_script("arguments[0].scrallIntoView();",link)
但是我有一个错误:
JavascriptException: Message: javascript error: arguments[0].scrallIntoView is not a function
(Session info: chrome=100.0.4896.127)
我的代码是:
driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')
driver.get('https://cordis.europa.eu/search/fr?q=contenttype%3D%27project%27%20AND%20programme%2Fcode%3D%27H2020%27&p=1&num=10&srt=/project/contentUpdateDate:decreasing')
driver.maximize_window()
time.sleep(10)
link = driver.find_element(By.XPATH,'//*[@id="c-main"]/div/div/section[2]/section[2]/app-card-search[1]/div/div[2]/a')
driver.execute_script("arguments[0].scrallIntoView();",link)
link.click()
time.sleep(5)
projet = driver.find_element(By.XPATH,'/html/body/app-root/ng-component/main/section/app-header-project/div/div/div[2]/h1')
print(projet.text)
driver.back()
感谢您的帮助。
您的脚本似乎有错字 scrallIntoView()
。
用 scrollIntoView()
更改它应该有效。
您好,我试图在 Selenium 中找到一个元素:
我发现:driver.execute_script("arguments[0].scrallIntoView();",link)
但是我有一个错误:
JavascriptException: Message: javascript error: arguments[0].scrallIntoView is not a function
(Session info: chrome=100.0.4896.127)
我的代码是:
driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')
driver.get('https://cordis.europa.eu/search/fr?q=contenttype%3D%27project%27%20AND%20programme%2Fcode%3D%27H2020%27&p=1&num=10&srt=/project/contentUpdateDate:decreasing')
driver.maximize_window()
time.sleep(10)
link = driver.find_element(By.XPATH,'//*[@id="c-main"]/div/div/section[2]/section[2]/app-card-search[1]/div/div[2]/a')
driver.execute_script("arguments[0].scrallIntoView();",link)
link.click()
time.sleep(5)
projet = driver.find_element(By.XPATH,'/html/body/app-root/ng-component/main/section/app-header-project/div/div/div[2]/h1')
print(projet.text)
driver.back()
感谢您的帮助。
您的脚本似乎有错字 scrallIntoView()
。
用 scrollIntoView()
更改它应该有效。