I want to open a a link on a webpage. The link appears to be within a unordered list which resides within in a tag. The url to the web page is selftechy dot com. The tabs are home, about, selenium.
I attempted to open the link using driver.findElement(By.linkText("Selenium")); but page seems like lost its styling. I also tried with xpath method, but it doesn't work either. Please explain to me why it doesn't work and how should I modify the code to make it work properly. Thanks for your help.
HTML code fragment:
<body class="custom">
<div id="container">
<div id="page">
<ul class="menu">
<li class="tab tab-home current"><a href="http://selftechy.com">Home</a></li>
<li class="tab tab-1"><a href="http://selftechy.com/about" title="About">About</a></li>
<li class="tab tab-2"><a href="http://selftechy.com/selenium-2" title="Selenium">Selenium</a></li>
</ul>
webdriver code to open the link
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class selftechyTestng
{
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
baseUrl = "http://selftechy.com/";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void searchElements() throws Exception{
driver.get(baseUrl);
//use By.linkText method the page lost its styling
driver.findElement(By.linkText("Selenium"));
//use xpath method to open the link doesn't work either
List<WebElement> elements = driver.findElements(By.xpath("//div[@id=page]/*[3]")).click();
driver.findElement(By.xpath("//div[@id=page]/*[3]")).click();
}
}