Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need Selenium to open it's web browser in a larger resolution ( preferably maximized)

Tags:

I am using Selenium WebDriver and coding in Python

I have looked all over the place and the best I could find were things written in different languages. I also tried to use the export tool on Selenium IDE but when I look at the data says that the function is not supported for export.

EDIT: The reason I need the browser to open up with a larger resolution is because the web application that I am testing is supporting tablet resolution as so elements are different depending on the resolution of the browser window.

This is the script I exported from the IDE with a couple of modifications.


from selenium import webdriver  from selenium.webdriver.common.by import By  from selenium.webdriver.support.ui import Select  from selenium.common.exceptions import NoSuchElementException  import unittest, time, re  from Funk_Lib import RS   class CreatingEditingDeletingVault(unittest.TestCase):     def setUp(self):         self.driver = webdriver.Firefox()         self.driver.implicitly_wait(30)         self.base_url = "http://cimdev-qa40/"         self.verificationErrors = []       def test_creating_editing_deleting_vault(self):         driver = self.driver         driver.get(self.base_url + "/Login?contoller=Home")         driver.find_element_by_id("UserName").click()         driver.find_element_by_id("UserName").clear()         driver.find_element_by_id("UserName").send_keys("[email protected]")         driver.find_element_by_name("Password").click()         driver.find_element_by_name("Password").clear()         driver.find_element_by_name("Password").send_keys("Codigo#123")         driver.find_element_by_id("fat-btn").click()         driver.get(self.base_url + "/Content/Vaults/")         driver.find_element_by_link_text("Content").click()         driver.find_element_by_link_text("Vaults").click()         driver.find_element_by_css_selector("button.btn.dropdown-toggle").click()         driver.find_element_by_link_text("New vault").click()         driver.find_element_by_name("Name").clear()         driver.find_element_by_name("Name").send_keys("Test Vault")         driver.find_element_by_xpath("//button[@onclick=\"vault_action('createvault', null, $('#CreateVault [name=\\'Name\\']').val())\"]").click()         driver.find_element_by_css_selector("button.btn.dropdown-toggle").click()         driver.find_element_by_link_text("Rename vault").click()         driver.find_element_by_name("Id").click()         Select(driver.find_element_by_name("Id")).select_by_visible_text("Test Vault")         driver.find_element_by_css_selector("option[value=\"2\"]").click()         driver.find_element_by_name("Name").clear()         driver.find_element_by_name("Name").send_keys("Test Change")         driver.find_element_by_xpath("//button[@onclick=\"vault_action('renamevault', $('#RenameVault [name=\\'Id\\']').val(), $('#RenameVault [name=\\'Name\\']').val())\"]").click()         driver.find_element_by_css_selector("button.btn.dropdown-toggle").click()         driver.find_element_by_link_text("Delete vault").click()         driver.find_element_by_name("Id").click()         Select(driver.find_element_by_name("Id")).select_by_visible_text("Test Change")         driver.find_element_by_css_selector("option[value=\"2\"]").click()         driver.find_element_by_xpath("//button[@onclick=\"vault_action('deletevault', $('#DeleteVault [name=\\'Id\\']').val(), '')\"]").click()      def is_element_present(self, how, what):         try: self.driver.find_element(by=how, value=what)         except NoSuchElementException, e: return False         return True      def tearDown(self):         self.driver.quit()         self.assertEqual([], self.verificationErrors)  if __name__ == "__main__":     unittest.main() 
like image 241
Korzin Avatar asked Nov 26 '12 19:11

Korzin


People also ask

How maximize screen using Selenium?

To maximize browser in Selenium, you need to call the maximize() Selenium command to maximize window interface of the driver class. void maximize() – This method is used to maximize the current browser.

What is the Selenium command to maximize the browser window?

1. Use the maximize() method from WebDriver. Window Interface.

How do I open Selenium browser full screen?

Same as pressing F11.


2 Answers

Selenium 2.31.0

driver = webdriver.Firefox()  # Resize the window to the screen width/height driver.set_window_size(300, 500)  # Move the window to position x/y driver.set_window_position(200, 200) 
like image 105
TONy.W Avatar answered Oct 06 '22 18:10

TONy.W


browser = webdriver.Firefox() url = 'http://www.google.com/' browser.get(url) browser.maximize_window() 
like image 22
Refnaldi Hakim Avatar answered Oct 06 '22 20:10

Refnaldi Hakim