我在webdriver中有一个测试,它同时打开多个Chrome浏览器,但是当它打开时它会相互重叠。但我想打开它们而不会在同一台显示器中相互重叠。这有可能,找不到具体的东西吗?
如果webdriver中有任何方法可以执行此操作,请告诉我。
谢谢
答案 0 :(得分:3)
虽然WebDriver没有特定的便捷方法来满足您的要求,但您可以通过确定显示器的高度/宽度并相应地设置窗口的大小和位置来以编程方式解决问题。
下面是一个如何使用Selenium库并行显示两个窗口的示例:
//Maximise the window size to determine the height and width available
driver.manage().window().maximize();
//Retrieve the size of the maximised window as a dimension
Dimension windowSize = driver.manage().window().getSize();
//Determine the desired height and width of the window and store it as a dimension
int desiredHeight = windowSize.height;
int desiredWidth = windowSize.width/2; //Half the screen width
Dimension desiredSize = new Dimension(desiredWidth, desiredHeight);
//Set the size of the window to the dimension determined above
driver.manage().window().setSize(desiredSize);
//Set the position of the window relative the upper left corner of the screen
driver.manage().window().setPosition(new Point(0, 0)); //Left side of screen
//OR
driver.manage().window().setPosition(new Point(targetWidth, 0)); //Right side of screen