代码之家  ›  专栏  ›  技术社区  ›  rocheteau

滚动查找Selenium中的元素

  •  0
  • rocheteau  · 技术社区  · 3 年前

    嗨,我试图寻找硒元素:

    我发现: 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()
    

    谢谢你的帮助。

    0 回复  |  直到 3 年前
        1
  •  2
  •   undetected Selenium    3 年前

    你的剧本好像有错 scrallIntoView() . 换成 scrollIntoView() 应该有用。

    推荐文章