I am getting below error even though I was using correct identifier.

No such element exception: Unable to locate element:

HTML Code:

<input type="text" name="UserName" class="md-input" id="input_001">

enter image description here

  • I have tried with @FindBy(name="UserName") as well, but it doesn't seem to be working Aug 23 '18 at 1:44
  • try xpath by.xpath(//input(@class='md-input'))[contains(text(),'UserName')] Aug 23 '18 at 5:34
  • your element is within the iFrame, so first try to switch that particular iframe and then try to locate that element. Aug 23 '18 at 14:14

You have element inside the iframe. So in Selenium, to work with element which is in embedded resource such as frame, you need to first switch into respective iframe and then perform the actions.

There are following ways to switch into frame :

  1. Switch to the frame by index :

  2. Switch to the frame by Name or ID attributes :

    e.g. <frame src="" name="adminPanel" id="some_id">

  3. Switch to the frame by Web Element

    WebElement frame = driver.findElement(By.locator);
  4. You can use ExplicitWait as well :

    new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@src,'')]")));

And then perform the action. In Page Factory fashion your element would be :

private WebElement username;

public WebElement getUsername(){
    return username;

public void sendUsername(String uname){
  • Hi @NarendraR sorry i could not understand your statements. Aug 23 '18 at 23:55
  • Pleaes let me know where should I include SwithTo Statement, i.e. in Page Class or Test Case class? Aug 24 '18 at 0:01
  • @DVadlamoodi, Test Case class
    – NarendraR
    Aug 24 '18 at 3:58
  • Thank you as you noticed, frame doesn't have any name or id. Aug 24 '18 at 4:22
  • new WebDriverWait(driver, 60).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@src,'')]"))); use this one, it will automatically find the frame and switch in. (replace the frame src attribute properly) and let me know further
    – NarendraR
    Aug 24 '18 at 6:18

You should be able to select it by using :

Public  Username By = By.id(“ input-001”);
  • Thank you! but it didn't work Aug 23 '18 at 23:58

This webelement is inside an Iframe. So switch into the Iframe first try the below code

private WebElement Input_001;

Then in the code Page Factory selenium is written as

public void userLogin(String Input){
  • Hi @Prasanna Can you please let me know where i should write code for Switch to Frame? is it in Page Class or Test Case class file? Sorry, i am very basic learner of Selenium Aug 23 '18 at 23:58
  • Hi @Vadlamoodi include the switchto statements before this line. @FindBy(id="input_001") Aug 24 '18 at 1:29
  • This is Page Class public class Login { @FindBy(how=How.NAME, using="UserName") private WebElement user; @FindBy(name="password") private WebElement pwd; @FindBy(name="signin") private WebElement submit; public Login (WebDriver driver) { PageFactory.initElements(driver, this); } public void applicationLogin() { user.sendKeys("xxxxx"); pwd.sendKeys("xxxxx"); submit.click(); } I don't thik it accepts driver statement below webelement declaration Aug 24 '18 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.