Tuesday, November 15, 2011

Selenium - Autosuggest edit field

keyPressNative method will be used to handle autosuggestion.
keyPressNative method -Simulates a user pressing and releasing a key by sending a native operating system keystroke. This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular element, focus on the element first before running this command.

public void selectAutosuggest(String webElementLocator,String inputValue){
char[] stringArray = inputValue.toUpperCase().toCharArray();
selenium.click(webElementLocator);
for(int i=0;i &lt stringArray.length ; i + +)
selenium.keyPress(webElementLocator,""+(int)stringArray[i]);
//Press downarrow and click EnterKey
selenium.keyPressNative(String.valueOf(KeyEvent.VK_DOWN));
selenium.keyPressNative(String.valueOf(KeyEvent.VK_ENTER));
Thread.sleep(1000);

}

Sunday, November 13, 2011

Selenium - XPATH - Location Of text...


If we want to click on some text which we dont know the Id,Name
we can use selenium.click("xpath=//*[text()=\"Search\"]")
To be more specific we can use
selenium.click("xpath=//*[@id='ParentDivId']//*[text()='Search']");



Wednesday, November 2, 2011

WebDriver - Listbox and few other details

In latest WebDriver , we have to use sendKeys to select a value from the listbox.
RenderedWebElement class has been depreceated.

Normal Driver instance can be as follows:
  firefox:
            FirefoxProfile firefoxProfile = new FirefoxProfile();
            firefoxProfile.setAcceptUntrustedCertificates(true);
            localDriver = new FirefoxDriver(firefoxProfile);
            localDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver = localDriver;
         
 iexplore:
            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(
     InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                            true);
            ieCapabilities
                    .setCapability(CapabilityType.HAS_NATIVE_EVENTS, true);
            ieCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
            ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            ieCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT,
                    true);
            localDriver = new InternetExplorerDriver(ieCapabilities);
           driver = localDriver;