使用Javascript和Selenium Webdriver(Chrome)登录 [英] Logging in using Javascript and Selenium Webdriver (Chrome)

查看:110
本文介绍了使用Javascript和Selenium Webdriver(Chrome)登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写脚本来访问Cisco无线LAN控制器.我正在使用Selenium和Chrome,并且停留在登录页面上.据我所知,单击Cisco启动屏幕上的登录"按钮会触发一个名为loginAction()的JavaScript,以提示用户输入用户名和密码.

I'm trying to write a script to access a Cisco Wireless LAN controller. I'm using Selenium and Chrome, and I'm stuck on the login page. From what I can tell, clicking the 'login' button on the Cisco splash screen triggers a javascript called loginAction() to prompt the user for a username and password.

我遇到的问题是弹出式登录框没有可识别的元素.显示登录框时,光标已在用户名字段中处于活动状态.看来我可以使用sendKeys函数在当前活动的文本框中输入用户名,但这是行不通的.由于我不知道文本框的ID,因此无法使用类似driver.findElement(By.id("authlogin")).sendKeys("username");

The problem I'm getting is that the popup login box has no identifiable elements. When the login box is displayed, the cursor is already active in the username field. It seems that I would be able to use the sendKeys function to simply enter a username in the currently active text box, but it doesn't work. Since I don't know the id of the text boxes, I can't use something like driver.findElement(By.id("authlogin")).sendKeys("username");

在其他论坛帖子中,我看到了常见的解决方案是在加载浏览器时在URL中嵌入用户名和密码,例如driver.get('

Looking at other forum posts, I've seen where a common solution is to embed the username and password in the URL when the browser is loaded, like driver.get('https://username:password@exampleurl.com'). I'm not having any luck with this either; it simply brings up the same splash screen and asks for credentials, just like if I had manually clicked the 'login' button on the splash screen.

有人对此有任何想法吗?由于光标在用户名文本框中已处于活动状态,因此这似乎非常简单.感谢您的帮助和建议!

Does anyone have any ideas on this? It seems like it would be fairly straightforward since the cursor is already active in the username text box. Thanks for any help and advice!

推荐答案

在登录应用程序时,我也面临着类似的问题.由于打开的用于登录的Windows身份验证弹出窗口不是基于浏览器的弹出窗口,因此Selenium无法与其直接交互.要与基于Windows的弹出窗口进行交互,您必须使用诸如AutoIT之类的第三方工具.在为AutoIT进行设置后,您只需在网址之后添加一行代码,如下所示

I too faced similar issue while logging into the application. Since the windows authentication popup opened for login is not browser based popup, so selenium cannot interact with it directly. To interact with windows based popup, you have to use third party tool like AutoIT. After doing setup for AutoIT you just have to add one line of code as shown below after your url

driver.get("http://your.url");
Runtime.getRuntime().exec("D:\\AutoIt\\AutoItTest.exe");//path where you kept exe file 

有关如何在AutoIT上工作的更多信息,请检查第二种方法 或浏览这篇文章

For more info on how work on AutoIT, check second approach here or go through this article

这篇关于使用Javascript和Selenium Webdriver(Chrome)登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆