【问题标题】:How correct scaling the page with Python + Selenium?使用 Python + Selenium 如何正确缩放页面?
【发布时间】:2022-01-21 06:55:18
【问题描述】:

我开始使用 python + selenium 学习自动化,但我遇到了问题: 当我使用这些脚本时:

self.driver.execute_script("document.body.style.transform = 'scale(0.8)'")self.driver.send_keys(Keys.CONTROL, Keys.SUBTRACT)webdriver.ActionChains(driver=webdriver.Chrome()).key_down(Keys.CONTROL).send_keys("-").perform()

我的测试站点的缩放比例不正确 - 缩放比例没有减小,但是沿边缘具有空白边框的页面只是移开并且布局崩溃(最后一个脚本不起作用并且不会因错误而停止)。请给我这个案子的最佳方法。
附言浏览器设置方法:

driver.get('chrome://settings/') driver.execute_script('chrome.settingsPrivate.setDefaultZoom(0.8)') driver.get("https://www.stackoverflow.com/")

工作得很好,但在这种情况下,Selinium 不能正确地与所有页面一起工作 - 它不能选择定位器..

【问题讨论】:

    标签: python selenium selenium-webdriver automation qa


    【解决方案1】:

    您可以尝试将浏览器窗口调整为更大的尺寸,而不是通过缩小来缩放页面。例如,将以下内容添加到您的 Chrome 选项中:

    options.add_argument("--window-size=1920,1080")
    

    【讨论】:

    • 这种方式行不通,因为窗口调整大小,但缩放已满(100%)并且 selen 还不能 ckick 到元素
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    相关资源
    最近更新 更多