How to Enter Password in a Popup Using Watir

Ruby Watir webdriver testing - how to loop through user/password

Yes, you could loop through key-value pairs by doing this:

logins = { 'username1' => 'password1', 'username2' => 'password2' } #And so on for your 5 accounts.
logins.each_pair do |user, pass|
b = Watir::Browser.new
b.goto 'https://localhost/mywebapp'
b.text_field(id:'username').set user
b.text_field(id:'password').set pass
b.button(id: 'submitBtn').click
end

An alternative would be to load the login details from a CSV file.

watir: How do I enter a value in a form, without submitting the form with watir?

I could tell you more if you posted relevant HTML or link (if page is public), but my guess is that entering password fires JavaScript event that submits the form. Access is denied. could mean that there is a frame, and IE does not allow access to it (http://wiki.openqa.org/display/WTR/Frames).

Maybe this would help:

ie.text_field(:name, "j_password").value=("password")

Using Watir I can't get a test to verify text in a username field

Text fields, specifically input elements, do not have a text node. As a result, you will get an empty string when using the text method on a text field. Similarly, there will be no text when calling browser.text.

The text you see in the text field is actually the value of the value attribute. You have to check that attribute instead. For example, you can use the value method:

browser.text_field(text: 'superuser').value.include? 'superuser'

Ruby/Watir disable Save password prompt

Using Preferences

You are setting the preferences correctly. The problem is that you're running into a bug in Selenium-WebDriver - https://github.com/SeleniumHQ/selenium/issues/7917.

Until the fix is released, you'll need to use Strings for the preferences instead of Symbols:

options.add_preference("credentials_enable_service", false)
options.add_preference("password_manager_enabled", false)

Note that you don not need to create the Selenium Options directly. You can let Watir do this for you:

browser = Watir::Browser.new(
:chrome,
options: {
options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
args: ["ignore-certificate-errors", "disable-infobars", '--disable-features=RendererCodeIntegrity'],
prefs: {"credentials_enable_service" => false, "password_manager_enabled" => false}
}
)

Using Incognito

Alternatively, instead of setting preferences, you could use incognito mode:

options = Selenium::WebDriver::Chrome::Options.new(
options: {"excludeSwitches" => ["enable-automation", "load-extension"]},
args: ["incognito", "ignore-certificate-errors", "disable-infobars"]
)


Related Topics



Leave a reply



Submit