Naveen
Naveen

Reputation: 9

Selenium.Unable to enter username and password for a website

I have two input fields username and password. I am unable to locate and enter the inputs using selenium. Login button click also fails.

Please find the HTML

    <div id="loginTable">
<form accept-charset="UTF-8" name="loginForm" method="POST" action="/cgi-bin/login">
<table>
<tbody>
<tr>
  <td>User name:</td><td colspan="2"><input name="LOGIN"></td></tr><tr>
  <td>Password:</td><td colspan="2"><input name="PWD" type="password"></td></tr><tr>
<td colspan="2"><button type="submit">Login</button></td></tr></tbody></table></form></div>

i have used below code lines,

driver.findElement(By.xpath("//[@id=\"loginTable\"]/form/table/tr[1]/td[2]/input")).sendKeys("test"); driver.findElement(By.name("LOGIN")).sendKeys("test");

WebElement userEntry=wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("LOGIN"))); userEntry.sendKeys("Test");

None of them are working.

Login button also not working. Please help me.

Upvotes: 0

Views: 1132

Answers (1)

Jsmith2800
Jsmith2800

Reputation: 1113

The issue is your locator. You need something to identify the type of element you're looking for at the start (e.g. "//div[@id...." or "//*[@id...." if you want it as a wildcard) However you can simplify your locator to:

//input[@name='LOGIN']

Compound locators like the one you've attempted to use can be very brittle, as there are more elements from your code that could potentially change.

Upvotes: 0

Related Questions