Nishant
Nishant

Reputation: 81

Selenium Webdriver click not working

I am trying to use the selenium webdriver to automate my testing I am using selenium 2.39.0 and firefox 26.0 I am tryign a simple example example for a click but its failing The element is selected because a sysout on the selected element text gives "create account".But its not able to click the button

 WebDriver driver = new FirefoxDriver();
driver.get("http://en.wikipedia.org/wiki/Main_Page");
System.out.println(driver.findElement(By.id("pt-createaccount")).getText());
driver.findElement(By.id("pt-createaccount")).click();
assertEquals("Create account - Wikipedia, the free encyclopedia", driver.getTitle());
driver.quit();

Any help is appreciated

Tried all the below things Got a reply from the selenium google group and this worked

Please open the system display settings and ensure that font size is set to 100%, see the attached screenshot. https://code.google.com/p/selenium/issues/detail?id=6756

Upvotes: 1

Views: 5036

Answers (2)

kiran
kiran

Reputation: 292

public class Wiki

{

     @Test
     public void createAccount() throws InterruptedException
     {
     WebDriver driver = new FirefoxDriver();
     WebDriverWait wait=new WebDriverWait(driver,60);
     driver.get("http://en.wikipedia.org/wiki/Main_Page");
     driver.findElement(By.linkText("Create account")).click();
     wait.until(ExpectedConditions.titleContains("Create account - Wikipedia, the free encyclopedia"));
     Assert.assertEquals("Create account - Wikipedia, the free encyclopedia",driver.getTitle());
     driver.quit();
     }

}

Upvotes: 0

Nat
Nat

Reputation: 274

You need to click on "a" element:

IWebElement createAccountLink = driver.findElement(By.id("pt-createaccount")).FindElement(By.TagName("a"));  
createAccountLink.Click();

Upvotes: 1

Related Questions