Showing posts with label JavaScriptExecutor in selenium web driver example. Show all posts
Showing posts with label JavaScriptExecutor in selenium web driver example. Show all posts

Wednesday 17 May 2017

Selenium-Tweaking proxy server for firefox and JavaScriptExecutor




how to bypass proxy in selenium webdriver, how to set proxy in firefox using selenium web driver, JavaScriptExecutor in selenium web driver example

Tweaking proxy server for firefox and JavaScriptExecutor

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 4);
profile.setPreference("network.proxy.http", "localhost");
WebDriver dr = new FirefoxDriver(profile);

Integer values are only allowed for the "network.proxy.type".

0 - Direct connection/ Proxy not allowed.
1 - Manual proxy
2 - Proxy auto-configuration
4 - Auto-detect proxy
5 - Use system proxy

While there are issues performing click on any element using element.click, JavaScriptExecutor can be used.
package com.p1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class JavaScriptExecutorEg {


       public static void  main(String[] args)  {


           FirefoxProfile profile = new FirefoxProfile();
           profile.setPreference("network.proxy.type", 4);
           profile.setPreference("network.proxy.http", "localhost");
           WebDriver dr = new FirefoxDriver(profile);

           dr.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

           dr.manage().window().maximize();
           dr.navigate().to("http://www.bing.com/");
           WebElement SignBTn = dr.findElement(By.id("id_l"));
           JavascriptExecutor executor = (JavascriptExecutor)dr;
           executor.executeScript("arguments[0].click();", SignBTn);

       }

}