-1

我想知道是否有人知道将文本输入到没有任何标识符的字段中。发生的情况是,我访问了一个网站,并在 Web 浏览器前显示了一个登录页面。如果我现在使用 F12,我会在后台收到有关该页面的所有信息,但登录页面除外。

有没有办法盲目输入文字,按tab,再输入一些,然后按回车?

4

2 回答 2

1

I will make wild guess: That log in page uses HTTP basic authentification and you need to get to that page using Selenium.

If so, simply use this:

 driver.get("http://username:password@your-test-site.com");

Where driver is healthy instance of WebDriver

EDIT In my testing, I had the same issues as you are having. So try this:

  1. Go to your test site manually
  2. Manually log in
  3. Grab the URL you have been redirected to. In my case its something like http://my-test-site.com/faces/pages/admin/admin.xhtml
  4. Use that url to get to the site - i.e: driver.get("http://username:password@my-test-site.com/faces/pages/admin/admin.xhtml");
于 2013-03-26T12:48:30.713 回答
1

假设您使用的是 firefox,您可以采取以下几种方法:

  1. 创建并使用您保存了用户名和密码的配置文件。

  2. 尝试在 Firefox 首选项中将您的域列入白名单,如下所示:

profile.SetPreference("network.automa

tic-ntlm-auth.trusted-uris", "domain.com");
driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://user:password@domain.com");
于 2013-03-26T13:20:11.183 回答