我有以下 Selenium java代码。
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@BeforeClass
public static void setUp() throws Exception {
driver = new RemoteWebDriver(new URL(System.getProperty("webDriverUrl")), DesiredCapabilities.firefox());
baseUrl = System.getProperty("baseUrl");
driver.get(baseUrl + "/");
}
@Test
public void testScreenSize(){
driver.manage().window().setSize(992, 768);
}
我似乎仍然无法调整窗口屏幕的大小。文本“window”被视为错误。知道为什么吗?
更新:
我现在可以运行代码了。它没有显示任何错误。这是因为依赖版本号。 这是我当前在 BeforeClass 中的代码。我的 Firefox 浏览器打开,但无法调整到我想要的大小。另外,我只需要它按宽度调整大小。高度并不重要。
driver = new RemoteWebDriver(new URL(System.getProperty("webDriverUrl")), DesiredCapabilities.firefox());
baseUrl = System.getProperty("baseUrl");
driver.get(baseUrl + "/");
driver.manage().window().setSize(new Dimension(992, 768));
最佳答案
这对我来说绝对没问题,在带有 FF41.0.2 的 selenium-server 2.48.2 上没有任何问题
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class SO35079080 {
static WebDriver driver;
@BeforeClass
public static void setUp() throws Exception {
driver = new RemoteWebDriver(new URL("WDURL"), DesiredCapabilities.firefox());
driver.get("https://www.google.co.in");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
@Test
public void testScreenSize(){
driver.manage().window().setSize(new Dimension(992, 768));
}
@AfterClass
public static void tearDown() {
driver.quit();
}
}
关于java - 调整屏幕尺寸以进行 Selenium 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35079080/