From Selenium 2.21, we can now maximize the browser window, similar to Selenium RC.
Direct way:
Indirect way:
we can also maximize the browser window usingt the toolkit utility which query the native operating system directly and is platform independent. In addition to this, the code below will maximize the browser window according to your system's current resolution.
Direct way:
public static void main(String[] args) {WebDriver d = new FirefoxDriver();d.get("http://www.google.com"); d.manage().window().maximize();
System.out.println(d.getTitle()); d.quit();}
Indirect way:
we can also maximize the browser window usingt the toolkit utility which query the native operating system directly and is platform independent. In addition to this, the code below will maximize the browser window according to your system's current resolution.
driver.manage().window().setPosition(
new
Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim =
new
Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
driver.manage().window().setSize(dim);
U
se the above script in your test setup method where you initiate the browser to get a fully maximized brwoser window that fits your monitor's screen size....
Thank you so much for the above code, it did worked for me though i searched lot of forums for the same but didn't get this simple information.
ReplyDeleteIs there isTextPresent() equent method in Webdriver ???????
ReplyDeletehi boss,
Deletedid u get the answer to your question?
The equivalent for it will be something like
assertTrue(driver.getPageSource().contains("sometext"));