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">
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">
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 :
Switch to the frame by index :
driver.switchTo().frame(0);
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");
Switch to the frame by Web Element
WebElement frame = driver.findElement(By.locator);
driver.switchTo().frame(frame);
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);
}
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
Commented
Aug 24, 2018 at 6:18
You should be able to select it by using :
Public Username By = By.id(“ input-001”);
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)
}