在 dialog/prompt 中输入密码
Enter password in dialog/prompt
如何在浏览器中输入密码 alert/dialog window。加载 url 时显示。它不是基本的身份验证提示,而是密码提示,它会阻止与页面的任何交互,直到输入密码。我将 selenium ruby 与 Capybara 一起使用。我尝试了以下方法:
page.driver.browser.switch_to.alert.send_keys("Password")
但它没有输入任何内容
这可能对您有帮助:
String Password = URLEncoder.encode("pass");
String UserName= URLEncoder.encode("UserName");
String url = String.format("http://%s:%s@xyz",
UserName, Password);
这里%s
是变量,以参数的形式传递给url。
也可以参考this url
如果你要填的是JS触发的系统模态window.prompt
那么你可以这样处理
page.accept_prompt(with: "The text to fill in") do
page.click_button "Go" # whatever action triggers the prompt to appear
end
如果它是系统身份验证模式(不是由 JS 打开),那么您无法从 Capybara 访问它,如果可以的话,您将不得不使用特定于您正在使用的平台的完整系统自动化工具'不要在您尝试访问的 URL 中传递凭据。
顺便说一句,如果你想连续出现很多提示,你可以封装它们:
page.accept_prompt("A prompt", with: "X") do
page.accept_prompt("Another prompt", with: "Y") do
page.click_button "Go" # Triggers two prompts
end
end
accept_prompt
的第一个参数(上面代码中的"A prompt"
resp. "Another prompt"
)是可选的;如果您提供它,将检查模态文本是否与参数匹配,如果不匹配则会出错。提示出现的顺序将在块的内部(首先 'another prompt' 然后 'prompt')
如何在浏览器中输入密码 alert/dialog window。加载 url 时显示。它不是基本的身份验证提示,而是密码提示,它会阻止与页面的任何交互,直到输入密码。我将 selenium ruby 与 Capybara 一起使用。我尝试了以下方法:
page.driver.browser.switch_to.alert.send_keys("Password")
但它没有输入任何内容
这可能对您有帮助:
String Password = URLEncoder.encode("pass");
String UserName= URLEncoder.encode("UserName");
String url = String.format("http://%s:%s@xyz",
UserName, Password);
这里%s
是变量,以参数的形式传递给url。
也可以参考this url
如果你要填的是JS触发的系统模态window.prompt
那么你可以这样处理
page.accept_prompt(with: "The text to fill in") do
page.click_button "Go" # whatever action triggers the prompt to appear
end
如果它是系统身份验证模式(不是由 JS 打开),那么您无法从 Capybara 访问它,如果可以的话,您将不得不使用特定于您正在使用的平台的完整系统自动化工具'不要在您尝试访问的 URL 中传递凭据。
顺便说一句,如果你想连续出现很多提示,你可以封装它们:
page.accept_prompt("A prompt", with: "X") do
page.accept_prompt("Another prompt", with: "Y") do
page.click_button "Go" # Triggers two prompts
end
end
accept_prompt
的第一个参数(上面代码中的"A prompt"
resp. "Another prompt"
)是可选的;如果您提供它,将检查模态文本是否与参数匹配,如果不匹配则会出错。提示出现的顺序将在块的内部(首先 'another prompt' 然后 'prompt')