Selenium RC

Finding objects/elements on web page using Selenium RC and Webdriver 

Selenium has API’s to get the element ID’s of the web page like Selenium.GetAllButtons();
Selenium.GetAllFields(); and more.
If you use the WebDriver than you can use the following code:

protected List findElements(By by) {
if (!(driver.findElements(by).isEmpty())){
log.info("elements " + by + " are found");
return driver.findElements(by);
}else{
log.warn("elements " + by + " are not found");
return driver.findElements(by);
}
}

By Pavandeep Puddupakkam on March 29, 2012 | Selenium RC, WebDriver | A comment?
Tags: , , ,

How to locate an element by Xpath with its dynamic title 

Example: I have two images
ImageHTMLCode
some_date1 and some_date2 are generated dynamically.
How to locate them using CSS locator ?
click css=img[title*='since'] : will not work because it won’t
make difference between the two images.

More…

By Pavandeep Puddupakkam on March 23, 2012 | Selenium RC, XPath | 3 comments
Tags: , , ,

Using selenium.GetAttribute in Webdriver 

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

public string GetAttribute(string xpath, string attribut)
{
string value = "";
if (IsElementPresent(xpath))
{
value = driver.FindElement(By.XPath(xpath)).GetAttribute(attribut);
}
return value;
}

By Pavandeep Puddupakkam on December 9, 2011 | Selenium RC, WebDriver | A comment?
Tags: , ,

Using selenium.Select in Webdriver 

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

public void Select(string xpath, string value)
{
driver.FindElement(By.XPath(xpath+"/option[.='"+value+"']")).Click();
}

Using selenium.Open in Webdriver 

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

public void Open(string URL)
{
driver.Navigate().GoToUrl(URL);
}

Verifying the canonical tag on a web page using Selenium GetLocation 

Here is an example to verify the canonical tag on a web page using Selenium GetLocation. The selenium script is written in C#

public int CheckCanonicalTag()
{
int resultcount = 0;
string URL = selenium.GetLocation();
if (selenium.IsElementPresent("//link[@rel='canonical' and @href='" + System.Web.HttpUtility.UrlDecode(URL) + "']"))
{
Console.WriteLine( "Canonical tags is present on the page :" + URL);
}
else
{
Console.WriteLine( "Canonical tags is not present on the page :" + URL);
resultcount++;
}
return resultcount;
}

More…

By Pavandeep Puddupakkam on November 17, 2011 | Selenium RC, Visual Studio 2010 | 1 comment
Tags: , , ,