Not recognizing text box while further code for radio button is written

19 views
Skip to first unread message

Sengar

unread,
Jul 28, 2015, 8:24:00 AM7/28/15
to Selenium Users
Hi,

i wrote code for selecting partial link text, link text, text box and then radio button.
Earlier code was working fine till text box selection and typing in it.
but now when i include code for radio button, it's throwing exception at text box selection line "NoSuchElementException".

//This code is for launching and closing the browser
package findelement;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class Browser{
WebElement element;
WebDriver driver; 
@BeforeMethod
public void launchBrowser(){
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver= new ChromeDriver();
}
@AfterMethod
public void closeBrowser(){

}
}

//Main class
package findelement;

import org.testng.annotations.Test;

@Test
public class Practice extends Browser{
public void practice(){
driver.findElement(By.partialLinkText("Partial Link Test")).click();
driver.findElement(By.linkText("Link Test")).click();
driver.navigate().back();
driver.findElement(By.name("firstname")).sendKeys("Priyanka");
driver.findElement(By.name("lastname")).sendKeys("Sengar");
element = driver.findElement(By.id("sex-1"));
element.click();
}
}

Exception:
FAILED: practice
org.openqa.selenium.NoSuchElementException: no such element


Thanks for anticipating help.

Mercious

unread,
Jul 28, 2015, 10:09:55 AM7/28/15
to Selenium Users, priyank...@gmail.com
element = driver.findElement(By.id("sex-1"));

Is this the line where the exception is thrown?

Looking at the site that indeed should not happen.

I only have one idea: Inspect the element with Firefox or Chrome or whatever and copy&paste the value under ID into your code. I had one case where the '-' sign was a very special one and thus different. 


Sengar

unread,
Jul 28, 2015, 2:36:48 PM7/28/15
to Selenium Users, hart...@gmx.de

Thanks..it worked with XPATH.
But reason behind not recognizing text box is somthing else as XPATH worked only for next line. 
After that getting same issue.
Reply all
Reply to author
Forward
0 new messages