Monday

Selenium - If Object exist or not

I want to verify for a label if it exists on the webpage or not. As
the website uses pagination if the element is not available on the
first page, it can be found on the next page too. I am using selenium
RC for Java.

for any object use isElementPresent . It return true if object exist
(selenium.isElementPresent("link=yourlinkname")!= false

Xpath also can be use instead of object name

boolean flag=Globals.selenium.isElementPresent("//div[@id='portlet-wrapper-126']/div[2]/div/div/form/div[7]/table/tbody/tr[3]/td[8]/ul/li/strong/span");

if(flag==true)
{
System.out.println(flag);
Globals.selenium.click("//div[@id='portlet-wrapper-126']/div[2]/div/div/form/div[7]/table/tbody/tr[3]/td[8]/ul/li/strong/span");
Globals.selenium.click("//a[contains(@href, \"javascript:_126_deleteOrganization('20727');\")]");
//assertTrue(Globals.selenium.getConfirmation().matches("^Are you sure you want to delete this[\\s\\S]$"));
}
else
{
Globals.selenium.click("//div[@id='portlet-wrapper-126']/div[2]/div/div/form/div[6]/table/tbody/tr[3]/td[8]/ul/li/strong/span");
Globals.selenium.click("link=Delete");

}


verify a label :
use isElementPresent(label Id),

if it's text on page as link then use isTextPresent().
selenium.isTextPresent("link text");

No comments:

Post a Comment