Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, July 21, 2015

The Simplest way to set proxy settings

Firefox:
String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
     .setFtpProxy(PROXY)
     .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);

IE & Chrome - Chrome will take same cofiguration what IE uses

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
     .setFtpProxy(PROXY)
     .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new InternetExplorerDriver(cap);


Monday, July 13, 2015

Use following simple method to get Id attribute using XPath,

public string GetIDxpath(string xPath)
        {
            string id = driver.findElement(By.XPath(@" + xPath + @")).GetAttribute("id");
            return id;
        }
Use following generic method to get list of descendent elements using XPath

public List<WebElement> FindDescendentsXPath(WebElement objectName)
        {
            List<WebElement> descendents = objectName.findElements(By.XPath(".//*"));
            return descendents;
        }