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

  • I have tried with @FindBy(name="UserName") as well, but it doesn't seem to be working – D Vadlamoodi Aug 23 '18 at 1:44
  • try xpath by.xpath(//input(@class='md-input'))[contains(text(),'UserName')] – sameer joshi 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. – Bharat Mane Aug 23 '18 at 14:14
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);
}
  • Hi @NarendraR sorry i could not understand your statements. – D Vadlamoodi 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? – D Vadlamoodi 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. – D Vadlamoodi Aug 24 '18 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 Aug 24 '18 at 6:18
0

You should be able to select it by using :

Public  Username By = By.id(“ input-001”);
  • Thank you! but it didn't work – D Vadlamoodi Aug 23 '18 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)
}
  • 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 – D Vadlamoodi Aug 23 '18 at 23:58
  • Hi @Vadlamoodi include the switchto statements before this line. @FindBy(id="input_001") – Prasanna venkatesh 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 – D Vadlamoodi 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.