Page scroll up or down in Selenium WebDriver (Selenium 2) using java

Scenario/Test steps: 1. Open a browser and navigate to TestURL 2. Scroll down some pixel and scroll up For Scroll down: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“window.scrollBy(0,250)”); OR, you can do as follows: jse.executeScript(“scroll(0, 250);”); For Scroll up: jse.executeScript(“window.scrollBy(0,-250)”); OR, jse.executeScript(“scroll(0, -250);”); Scroll to the bottom of the page: Scenario/Test steps: … Read more

Getting console.log output from Chrome with Selenium Python API bindings

Ok, finally figured it out: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # enable browser logging d = DesiredCapabilities.CHROME d[‘loggingPrefs’] = { ‘browser’:’ALL’ } driver = webdriver.Chrome(desired_capabilities=d) # load the desired webpage driver.get(‘http://foo.com’) # print messages for entry in driver.get_log(‘browser’): print(entry) Entries whose source field equals ‘console-api’ correspond to console messages, and the message … Read more

Access to file download dialog in Firefox

I have a solution for this issue, check the code: FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference(“browser.download.folderList”,2); firefoxProfile.setPreference(“browser.download.manager.showWhenStarting”,false); firefoxProfile.setPreference(“browser.download.dir”,”c:\\downloads”); firefoxProfile.setPreference(“browser.helperApps.neverAsk.saveToDisk”,”text/csv”); WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub”), capability); driver.navigate().to(“http://www.myfile.com/hey.csv”);

How do you tell if a checkbox is selected in Selenium for Java?

If you are using Webdriver then the item you are looking for is Selected. Often times in the render of the checkbox doesn’t actually apply the attribute checked unless specified. So what you would look for in Selenium Webdriver is this isChecked = e.findElement(By.tagName(“input”)).Selected; As there is no Selected in WebDriver Java API, the above … Read more