问题描述
我正在开发一个在 reactjs 中开发的应用程序,并在 Mac 和 Win 上的一些桌面应用程序的 CEF 中工作,我已经使用 selenium 在调试点上使用远程调试实现了自动化。
一切正常,但现在他们将 UI 实现更改为延迟加载,因为 scrollIntoView()
停止工作。
另外,我希望获得 driver.get_window_size()
但它给出了以下错误:
selenium.common.exceptions.WebDriverException: Message: unkNown error: operation is unsupported with remote debugging
我正在寻找任何指导,通过它我们可以获得 CEF 框架/面板下的 chrome 大小,以便我可以编写一些逻辑来调整元素滚动。
以下是我尝试过的:
from selenium import webdriver
import os
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
element = driver.find_element(By.XPATH,"someXpath")
选项 1:
coordinates = element.location_once_scrolled_into_view # element appear on lower side of screen
driver.execute_script('window.scrollTo({},{});'.format(coordinates['x'],coordinates['y'])) # nothing happen after this
选项 2:
driver.execute_script("arguments[0].scrollIntoViewIfNeeded(true)",element) #nothing happen with this also
选项 3:
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth',block: 'center',inline: 'nearest'})",element) #nothing happen with this also
选项 4:
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollWidth",element)
选项 5:
driver.execute_script("arguments[0].scrollIntoView();",element)
选项 6:
desired_y = (element.size['height'] / 2) + element.location['y']
current_y = (driver.execute_script('return window.innerHeight') / 2) + driver.execute_script('return window.pageYOffset')
scroll_y_by = desired_y - current_y
driver.execute_script("window.scrollBy(0,arguments[0]);",scroll_y_by)
但以上都没有帮助将元素滚动到窗口中间,尽管脚本执行没有任何错误
- 平台:Win 10 和 Mac 10.15
- 硒:3.141.0
- Python:3.8.x
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)