gpt4 book ai didi

javascript - Selenium鼠标滚轮下拉加载所有页面

转载 作者:行者123 更新时间:2023-11-29 22:47:41 25 4
gpt4 key购买 nike

模拟鼠标滚轮加载所有元素。

mouse

我用 Google 搜索并尝试了很多但都失败了。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Configuration information
email = "*******"
password = "*******"

driver = webdriver.Chrome()
index_url = "https://quip.com/"
driver.get(url=index_url)
driver.find_element_by_xpath('//*[@id="header-nav-collapse"]/ul/li[9]/a').click() # click login
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/form/div/input').send_keys(email) # input email
driver.find_element_by_xpath('//*[@id="email-submit"]').click()
time.sleep(1)
driver.find_element_by_xpath('/html/body/div/div/form/div/input[2]').send_keys(password) # input password
driver.find_element_by_xpath('/html/body/div/div/form/button').click()
time.sleep(2)

下拉滚动条

js="var q=document.documentElement.scrollTop=100000" driver.execute_script(js)
time.sleep(3)
driver.maximize_window()
driver.find_element_by_xpath("xpath").send_keys(Keys.DOWN)
js="var q=document.documentElement.scrollTop=10000"
driver.execute_script(js)

上面的方法不行

最佳答案

要向下滚动网页 https://testselenium.quip.com/ 直到最后一个条目,您必须为 visibility_of_element_located() 引入 WebDriverWait 并且您可以使用以下 Locator Strategies :

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("start-maximized")
    #chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    #chrome_options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://quip.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn-sm[href='/account/login']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']"))).send_keys("187069474@qq.com")
    driver.find_element_by_css_selector("button#email-submit").click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='password']"))).send_keys("Huangbo1019@")
    driver.find_element_by_css_selector("button.submit").click()
    driver.execute_script("arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.nav-inbox-import-title"))))
  • 浏览器快照:

quip

Here you can find a relevant detailed discussion on What is the difference between the different scroll options?

关于javascript - Selenium鼠标滚轮下拉加载所有页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58055018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com