Link verification in Selenium Webdriver.

1,399 views
Skip to first unread message

Sudhansu Sekhar panda

unread,
Apr 22, 2013, 1:56:31 AM4/22/13
to seleniu...@googlegroups.com
Hi All,

Suppose i have a text "testing". I want to verify whether it  is a link text or a normal text.

How to verify that a text is a normal text or link text?

Can anyone please explain me through code?

Thanks,

Sudhansu

Ripon Al Wasim

unread,
Apr 22, 2013, 3:51:57 AM4/22/13
to seleniu...@googlegroups.com
You can do as follow for checking as Link text:

String s = driver.findElement(By.xpath("xpathOfText")).getTagName();
assertEquals(s, "a");

br,
Ripon


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/sblDMxldjN8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ARK Satyanarayana Raju

unread,
Apr 22, 2013, 4:09:07 AM4/22/13
to seleniu...@googlegroups.com
Try like this

//Check whether the text is link name or not
package Practice_pack_1;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CheckTextisLinkNameorNot {
   
WebDriver driver;
   
@BeforeTest
   
public void open()
   
{
        driver
=new FirefoxDriver();
          driver
.manage().window().maximize();
        driver
.get("http://www.google.com/");
   
}
   
@AfterTest
   
public void close()
   
{
        driver
.quit();
   
}
   
@Test
   
public void textcompare()
   
{
       
List<WebElement> elements=driver.findElements(By.tagName("a"));
       
int totallinks=elements.size();
       
for(int i=0; i< totallinks; i++)
       
{
           
String element= elements.get(i).getText();
           
String av="News";
           
if(av.equals(element))
           
{
               
System.out.println("News is link text");
           
}
           
else
           
{
               
//System.out.println("News is not a link text");
           
}
       
}
   
}
}

Fakrudeen Shahul

unread,
Apr 22, 2013, 4:11:29 AM4/22/13
to seleniu...@googlegroups.com
if driver.findElementByLinkText("link text") returns element then it is link text else if it throws exception then it is a normal text.
Reply all
Reply to author
Forward
0 new messages