0

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?

2

2 Answers 2

2
  1. Your webpage login request is under a frame so first we need to switch to the frame and then find element.

    &lt frameset &gt 
    &lt frame src='/retail3/loginfo/loginRequest' name="mainFrame" 
    scrolling="auto" noresize &gt
    &lt/frameset&gt
    

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();
  1. Login directly with the url below. It does not contain a frame:

    This link

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.