Reputation: 7563
I want to try to login to this website
This is my code :
driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName");
This is property for input text with id='userid_sebenarnya'
<div class="form-group" id="form-group-height">
<label for="userid" class="text-field-label-horizontal-empty">User ID</label>
<input id="userid" class="fake_field_userid" style="-webkit-box-shadow: inset 0 0 0 2em transparent !important" value="autofill field" type="text">
<div class="outer-border-login">
<input class="form-control-login-transparent" id="userid_sebenarnya" placeholder="Masukkan user ID" onblur="removeErrMsg('#userid');" data-rule-required="true" data-msg-required="Field ini dibutuhkan" autocomplete="off" readonly="" onfocus="this.removeAttribute('readonly'); this.focus();" value="" autocorrect="off" autocapitalize="off" spellcheck="false" maxlength="2147483647" style="-webkit-box-shadow: inset 0 0 0 2em transparent !important" type="text">
</div>
</div>
But I got error message like bellow, whereas it should be found if I look visually.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"userid_sebenarnya"}
Is this related to the hidden text input, what can I do?
Upvotes: 0
Views: 1123
Reputation: 4587
Your webpage login request is under a frame so first we need to switch to the frame and then find element.
< frameset >
< frame src='/retail3/loginfo/loginRequest' name="mainFrame"
scrolling="auto" noresize >
</frameset>
JAVA Code:
driver.get("the_site");
driver.switchTo().frame("mainFrame");
driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName");
driver.findElement(By.id("pwd_sebenarnya")).sendKeys("myUserName");
driver.findElement(By.id("btnSubmit")).click();
Login directly with the url below. It does not contain a frame:
Upvotes: 2
Reputation: 1
Try to use this xpath instead of id
driver.findElement(By.xpath("//*[contains(@id,'userid_sebenarnya')]")).sendKeys("myUserName");
driver.findElement(By.xpath("//*[contains(@id,'pwd_sebenarnya')]")).sendKeys("myPassword");
driver.findElement(By.xpath("//*[contains(@id,'btnSubmit')]")).click();
I checked this on the given website and it worked for me
Upvotes: 0