无法访问Chrome中的登录容器元素

无法访问Chrome中的登录容器元素

本文介绍了无法访问Chrome中的登录容器元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PAYTM 网站,然后单击登录按钮,然后打开了一个登录容器.我试图输入用户名和密码,但由于无法访问元素而无法继续.窗口处理程序,但它为主窗口和容器窗口返回相同的窗口ID.

I am using PAYTM site and click on the login button then a login container opened up .I tried to enter username and password but unable to proceed as am not able to access the elements.I tried window handler but it returns the same window id for main window and container window.

站点:- https://paytm.com/

我正在使用以下代码:-

I am using below code:-

driver.get("paytm.com");
String mainwindow = driver.getWindowHandle();
driver.findElement(By.xpath("//a[@class='login']")).click();
driver.findElement(By.name("username")).sendKeys(uname);
driver.findElement(By.name("password")).sendKeys(pwd);
driver.findElement(By.xpath("//button[@type='submit']")).click();

HTML代码:-

<input type="text" name="username" ng-class="{'number-new': ((sessionData.email | isMobile) &amp;&amp; loginForm.username.$dirty &amp;&amp; !loginForm.username.$error.required)}" ng-model="sessionData.email" data-required="" email-validate="" mobile-validate="" maxlength="30" data-ng-trim="false" class="ng-pristine md-input ng-invalid ng-invalid-required ng-valid-maxlength ng-valid-parse ng-valid-mobile-valid ng-valid-email-valid ng-touched" tabindex="0" id="input_0" aria-required="true" aria-invalid="true">

推荐答案

您必须先切换到iframe,然后才能找到用户名和密码元素.参见下面的代码:

You have to switch to iframe before finding username and password elements. See code below:

driver.get("https://paytm.com/");
driver.findElement(By.xpath("//a[@class='login']")).click();
try {
    Thread.sleep(3000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[ng-hide='showVerificationScreen']")));
driver.findElement(By.name("username")).sendKeys(uname);
driver.findElement(By.name("password")).sendKeys(pwd);
driver.findElement(By.xpath("//button[@type='submit']")).click();

P.S.您可以使用Chrome devtool,firebug或其他工具来确定元素是否位于iframe中.屏幕截图显示username元素位于iframe中.

P.S. You can determine if your element is in iframe or not by using Chrome devtool, firebug, or others. The screenshot shows that username element is inside an iframe.

这篇关于无法访问Chrome中的登录容器元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:35