我正在尝试从特定的div
元素缩小,或者只是从整个页面缩小。
我想缩小的原因是要解决另一个我有here的问题,其中我要计算很多动态元素并避免使用滚动条。
我已经尝试对ActionChains
和send_keys
标签都使用html
和body
。
第一次尝试:
ActionChains(driver).send_keys(driver.find_element_by_tag_name("html"), Keys.CONTROL, Keys.SUBTRACT, Keys.NULL).perform()
第二次尝试:
driver.find_element_by_tag_name("body").send_keys(Keys.CONTROL, Keys.SUBTRACT)
以上解决方案均未更改页面中的任何内容。我在非无头模式下运行此命令只是为了检查是否有所更改。我不确定是什么问题。这些是我的chrome
驱动程序属性,但我也希望能够在Firefox中进行缩小。
opts = webdriver.ChromeOptions()
# opts.add_argument("headless")
opts.add_argument('disable-gpu')
opts.add_argument("no-sandbox")
opts.add_argument("incognito")
opts.add_argument('disable-infobars')
prefs = {"profile.default_content_setting_values.notifications": 2}
opts.add_experimental_option("prefs", prefs)
exec_path = conf_object.config_map(
'Machine')["drivers_loc"] + 'chromedriver.exe'
browser = webdriver.Chrome(executable_path=exec_path, options=opts)
browser.set_window_size(1920, 937)
browser.maximize_window()
browser.delete_all_cookies()
browser.implicitly_wait(int(conf_object.config_map('Test')['wait']))
browser.set_page_load_timeout(
int(conf_object.config_map('Test')['wait']))
browser.set_script_timeout(int(conf_object.config_map('Test')['wait']))
您是否发现了使用python中的action类而不使用execute_script的解决方案?