How to continously scroll down a page until an element is located? Python selenium

前端 未结 3 1918
轮回少年
轮回少年 2021-01-24 16:06

I\'m baffled by the load more button for the skills section in Linkedin. I receive this error in finding the xpath for the button: selenium.common.exceptions.NoSuchElemen

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 16:55

    Try below code :

    from selenium import webdriver
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    
    
    driver = webdriver.Chrome(executable_path="C:\New folder\chromedriver.exe")
    
    driver.get('https://www.linkedin.com/login?fromSignIn=true&trk=guest_homepage-basic_nav-header-signin')
    driver.maximize_window()
    
    WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.NAME, "session_key"))).send_keys("email id")
    WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.NAME, "session_password"))).send_keys("password")
    WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[@class='btn__primary--large from__button--floating']"))).click()
    
    driver.get("https://www.linkedin.com/in/kate-yun-yi-wang-054977127/?originalSubdomain=hk")
    driver.maximize_window()
    
    buttonClick = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//span[text()='Show more']")))
    ActionChains(driver).move_to_element(buttonClick).click().perform()
    

    Output:

提交回复
热议问题