WebDriver

Using JavascriptExecutor to type text in a rich text editor box 

This is a solution for the Selenium Webdriver Type command not working on IE when you are trying to enter some text in a rich text editor. You can use the below code to execute the command in IE and other browsers.

((JavascriptExecutor)driver).executeScript("document.getElementById('ElementID').value='TextValue'");

The rich text editor is usually placed in a iFrame.

By Pavandeep Puddupakkam on February 20, 2012 | WebDriver | A comment?
Tags: , ,

Launching Webdriver on Google Chrome custom profile 


String chromeProfile =
ArrayList switches = new ArrayList();
switches.add("--user-data-dir=" + chromeProfile);
capabilities.setCapability("chrome.switches", switches);
driver = new ChromeDriver(capabilities);

By Pavandeep Puddupakkam on December 20, 2011 | WebDriver | A comment?
Tags: , ,

Using selenium.Close in Webdriver 

Here is the Selenium RC code for selenium.Close in Webdriver. This code is in Visual Studio C#

public void Close()
{
driver.Close();
}

By Pavandeep Puddupakkam on December 14, 2011 | WebDriver | A comment?
Tags: , ,

Using selenium.GetSelectedLabel in Webdriver 

Here is the Selenium RC code for selenium.GetSelectedLabel in Webdriver. This code is in Visual Studio C#

public string GetSelectedLabel(string xpath)
{
string text = "";
if (driver.FindElement(By.XPath(xpath)).Selected)
{
text = GetText(xpath + "/option[@selected]");
}
return text;
}

Using selenium.GetSelectedIndex in Webdriver 

Here is the Selenium RC code for selenium.GetSelectedIndex in Webdriver. This code is in Visual Studio C#

public string GetSelectedIndex(string xpath)
{
string text="";
int statenum = Convert.ToInt32(GetXpathCount(xpath+"/option"));
for (int i = 1; i < statenum; i++)
{
if (IsElementPresent(xpath+"/option[" + i + "][@selected]"))
{
text = Convert.ToString((i - 1));
}
}
return text;
}

Using selenium.SelectedLabel in Webdriver 

Here is the Selenium RC code for selenium.SelectedLabel in Webdriver. This code is in Visual Studio C#

public string SelectedLabel(string xpath)
{
string text = "";
if (IsElementPresent(xpath))
{
text = GetValue(xpath + "/following-sibling::label");
}
return text;
}