Arya
Arya

Reputation: 260

Selenium Java code cannot catch textbox

I'm not able to read this textbox to type in some text. The webpage is a login screen for Business Objects SAP tool.

Here's the HTML-

<div class="logon_table" >
<div id="userName" class="logon_input" >
<label class="logon_input_label" tabindex="-1" for="usernameTextEdit" > ... </label>
<input id="usernameTextEdit" class="inputTextBox logonTextBox" type="text" value="****" name="username" ></input>
</div>
**Same for passwordTextEdit
</div>

I tried the following but to no avail. Also, tried with XPath but not sure if I'm making a correct syntax to reach usernameTextEdit-

driver.findElement(By.id("usernameTextEdit")).clear();
driver.findElement(By.id("usernameTextEdit")).sendKeys("SomeUserName");                             

Upvotes: 1

Views: 218

Answers (1)

Walery Strauch
Walery Strauch

Reputation: 7062

You have iframe in this site. You have to switch there first.

This should work:

WebElement iframe = webDriver.findElement(By.id("infoView_home"));
webDriver.switchTo().frame(iframe);

webDriver.findElement(By.id("usernameTextEdit")).clear();
webDriver.findElement(By.id("usernameTextEdit")).sendKeys("SomeUserName");

webDriver.findElement(By.id("passwordTextEdit")).clear();
webDriver.findElement(By.id("passwordTextEdit")).sendKeys("Some Password");

Upvotes: 1

Related Questions