0

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

No such element exception: Unable to locate element:
{"method":"id","selector":"input_001"}

HTML Code:

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

enter image description here

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

3 Answers 3

1

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 :

    driver.switchTo().frame(0);
    
  2. Switch to the frame by Name or ID attributes :

    e.g. <frame src="http://52.24.63.155/lifepal/AdminPanel" name="adminPanel" id="some_id">

    driver.switchTo().frame("adminPanel");
    driver.switchTo().frame("some_id");
    
  3. Switch to the frame by Web Element

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

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

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

@FindBy(id="input_001")
private WebElement username;

public WebElement getUsername(){
    return username;
}

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

You should be able to select it by using :

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

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

@FindBy(id="input_001")
private WebElement Input_001;

Then in the code Page Factory selenium is written as

public void userLogin(String Input){
Input_001.sendKeys(Input)
}
3
  • 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 Commented Aug 23, 2018 at 23:58
  • Hi @Vadlamoodi include the switchto statements before this line. @FindBy(id="input_001") Commented Aug 24, 2018 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 Commented Aug 24, 2018 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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