我想尝试登录网络。这是我的代码:
public static void main(String[] args) throws IOException, InterruptedException, AWTException {
System.setProperty("webdriver.chrome.driver", "D:\\BrowserDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://ibank.bankmandiri.co.id");
TimeUnit.SECONDS.sleep(10);
driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName");
driver.findElement(By.id("pwd_sebenarnya")).sendKeys("myPassword");
driver.findElement(By.id("btnSubmit")).click();
TimeUnit.SECONDS.sleep(10);
driver.quit();
}
这是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>
但是我收到了类似波纹管的错误消息,但是如果我用肉眼看应该找到它
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"userid_sebenarnya"}
这与隐藏文本输入有关,该怎么办?预先感谢
答案 0 :(得分:1)
您的网页登录请求在一个框架下,因此我们首先需要切换到该框架,然后找到元素。
< frameset >
< frame src='/retail3/loginfo/loginRequest' name="mainFrame"
scrolling="auto" noresize >
</frameset>
JAVA代码:
driver.get("https://ibank.bankmandiri.co.id");
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();
使用下面的URL直接登录。它不包含框架:
https://ibank.bankmandiri.co.id/retail3/loginfo/loginRequest
答案 1 :(得分:0)
尝试使用此xpath代替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();
我在给定的网站上进行了检查,它对我有用