[英]How to set the size of the selenium window? (in python, on Mac, using chromedriver)
So this is just weird. 所以这很奇怪。 I can't seem to do a very simple task with selenum; 我似乎无法对selenum做一个非常简单的任务。 change the size of the window. 更改窗口的大小。 As the title states, im using Python on a Mac and specifically using chromedriver. 如标题所示,即时通讯在Mac上使用Python,特别是在chromedriver中使用。
I have tried this: 我已经试过了:
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=200,200")
driver = webdriver.Chrome(executable_path=EXE_PATH, chrome_options=options)
I've tried changing "window-size" to "--window-size" and removed the headless option. 我尝试将“ window-size”更改为“ --window-size”,并删除了无头选项。 I've also tried using set_window_size after opening the page I want. 打开所需的页面后,我也尝试过使用set_window_size。 None of it works. 没有一个有效。 set_window_size actually gives an error and the above use of the Options class doesnt crash but the window stays the same size it always is. set_window_size实际上给出了一个错误,并且上面对Options类的使用没有崩溃,但是窗口保持与以前相同的大小。
I found this thread from 2012: 我从2012年发现了这个线程:
Mac selenium webdriver chrome window always starts with a small window Mac Selenium WebDriver Chrome窗口始终以小窗口开头
But can't believe a library as popular as selenium still doesn't offer a way to resize windows easily, and can't find any other suggestions beyond those tweaks I already said I tried. 但是不能相信像硒这样流行的库仍然无法提供轻松调整窗口大小的方法,并且除了我已经说过的那些调整之外,找不到其他建议。 Thanks. 谢谢。
i guess you can try 我想你可以试试
from selenium.webdriver import Chrome
driver = Chrome()
driver.set_window_position(0, 0)
driver.set_window_size(1024, 768)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.