gpt4 book ai didi

javascript - Selenium 蟒 : How to Scroll Down in a Pop Up window

转载 作者:行者123 更新时间:2023-11-30 15:04:38 27 4
gpt4 key购买 nike

我正在从事 Linkedin 网络抓取项目。我正在尝试获取某人感兴趣的公司列表(注意我没有使用 API)。这是一个动态网站,所以我需要在抓取公司名称的同时向下滚动。我知道如何在主窗口中执行此操作,但由于 Interest 是一个弹出窗口 this滚动的解决方案不起作用。到目前为止我的代码是:

from selenium.webdriver.common.keys import Keys
bar = driver.find_element_by_xpath('//ul[@class="entity-list row"]')
bar.send_keys(Keys.END)

既然不行,我也试了:

bar = driver.find_element_by_xpath('//ul[@class="entity-list row"]')
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', bar)

问题是我不是在弹出窗口上操作而是在主窗口上操作,所以它没有达到预期的效果。

enter image description here

最佳答案

您可以尝试在弹出窗口中找到元素(可以聚焦的元素),例如一些 anchor :

element_inside_popup = driver.find_element_by_xpath('//div[@class="entity-list-wrapper ember-view"]//a')

然后使用下面的代码向下滚动弹出窗口:

from selenium.webdriver.common.keys import Keys

element_inside_popup.send_keys(Keys.END)

关于javascript - Selenium 蟒 : How to Scroll Down in a Pop Up window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45961116/

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