Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在selenium(python)中打开之前设置chromedriver窗口大小_Python_Python 3.x_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

在selenium(python)中打开之前设置chromedriver窗口大小

在selenium(python)中打开之前设置chromedriver窗口大小,python,python-3.x,selenium,selenium-webdriver,selenium-chromedriver,Python,Python 3.x,Selenium,Selenium Webdriver,Selenium Chromedriver,当我的脚本在Windows 10中打开chromedriver driver=webdriver.Chrome时,我的显示器上的窗口将最大化到最大。为了最大限度地减少干扰,我宁愿它几乎不引人注目。我能得到的最接近的结果如下: driver = webdriver.Chrome() driver.set_window_size(1, 1) 这在窗口大小最小的情况下运行良好。不幸的是,它仍然会首先打开整个显示器,然后重新调整到首选的最小尺寸。在打开chromedriver之前,有没

当我的脚本在Windows 10中打开chromedriver driver=webdriver.Chrome时,我的显示器上的窗口将最大化到最大。为了最大限度地减少干扰,我宁愿它几乎不引人注目。我能得到的最接近的结果如下:

    driver = webdriver.Chrome()
    driver.set_window_size(1, 1)
这在窗口大小最小的情况下运行良好。不幸的是,它仍然会首先打开整个显示器,然后重新调整到首选的最小尺寸。在打开chromedriver之前,有没有办法预设窗口大小?

您可以放置驱动程序。在设置方法中设置窗口大小1,1,例如:

class ExampleTestSuite(unittest.TestCase):
   def setUp(self):
      self.driver= webdriver.Chrome()
      self.driver.set_window_size(1,1)

  def test_example_test(self):
     #test code here
我认为你真正想要的是无头运行你的测试。有一种方法可以做到这一点,请在本文中描述:

另一种选择是使用基于云的测试服务,如Sauce Labs或Browserstack。

您可以放置驱动程序。在设置方法中设置窗口大小1,1,例如:

class ExampleTestSuite(unittest.TestCase):
   def setUp(self):
      self.driver= webdriver.Chrome()
      self.driver.set_window_size(1,1)

  def test_example_test(self):
     #test code here
我认为你真正想要的是无头运行你的测试。有一种方法可以做到这一点,请在本文中描述:


另一个选择是使用基于云的测试服务,如Sauce Labs或Browserstack。

事实上,我找到了一个非常好的替代@user3277225答案的方法。事实证明,您可以为Chrome webdriver设置选项,然后按如下方式打开它:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("window-size=1,1")
driver = webdriver.Chrome(chrome_options=chrome_options)

事实上,我找到了一个非常好的替代@user3277225答案的方法。事实证明,您可以为Chrome webdriver设置选项,然后按如下方式打开它:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("window-size=1,1")
driver = webdriver.Chrome(chrome_options=chrome_options)

我在看被接受的答案,我在看你的问题,你知道吗?被接受的答案正是我从阅读你的问题中了解到的。所以你的问题不清楚一个用户能够读懂你的想法这一事实并不清楚。请用你正在使用的实际测试代码编辑它,然后它将是一个有用的问题。我正在看接受的答案,我正在看你的问题,你知道吗?被接受的答案正是我从阅读你的问题中了解到的。所以你的问题不清楚一个用户能够读懂你的想法这一事实并不清楚。请用您使用的实际测试代码编辑它,然后它将是一个有用的问题。这是一个有趣的选择。但是,如果您在多个浏览器上运行selenium测试,似乎只需在设置方法中设置浏览器窗口,而不是为每个浏览器设置选项,会更容易。这是一个有趣的选择。但是,如果您在多个浏览器上运行selenium测试,则似乎只需在设置方法中设置浏览器窗口比为每个浏览器设置选项更容易。