I'm brand new to Watir. I'm using SafariWatir on a fully updated MBP Snow Leopard.
So far I've successfully used
goto, link, text_field, and button
but when I try to access a text_field with
type="password" name="pass" id="pass"
(as seen in Web Inspector) with
browser.text_field(:id, "pass") or
browser.text_field(:name, "pass")
I get
Watir::Exception::UnknownObjectException: Unable to locate TextField
There's a very simple answer:
In Watir and FireWatir, a password field is called
text_field
In SafariWatir, a password field is called
password
So, to access a input of type=password, I needed to use
browser.password(:id, "pass")
or
browser.password(:name, "pass")
This solved my problem.
Notes: I'm using mac 10.8,ruby 1.9.3;
The working sample is: browser.password(:name,'password').set'yourpassword'
There is no space between set and the value.
Related
I am trying to login to a site and I am using FindElementById. In the following code the first part of using SendKeys works well but when trying to use the same technique for the password field, I get an error message which tells me that the element is not interactable
Sub Test()
Dim bot As New WebDriver
With bot
.AddArgument "--disable-notifications"
.Start "Chrome", "https://www.excelforum.com/excel-programming-vba-macros/"
.Get "/"
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password").SendKeys "password"
'.FindElementByName("vb_login_password").SendKeys "password"
Stop
End With
End Sub
You were pretty close. The Password field with id attribute as navbar_password is having the property:
style="display: none;"
So you won't be able to interact with the element.
To send a character sequence both to the User Name and Password field you can use either of the following Locator Strategies:
Using FindElementById():
.FindElementById("navbar_username").SendKeys "username"
.FindElementById("navbar_password_hint").SendKeys "password"
Using FindElementByCss():
.FindElementByCss("input#navbar_username").SendKeys "username"
.FindElementByCss("input#navbar_password_hint").SendKeys "password"
Using FindElementByXPath():
.FindElementByXPath("//input[#id='navbar_username']").SendKeys "username"
.FindElementByXPath("//input[#id='navbar_password_hint']").SendKeys "password"
References
You can find a couple of revelant discussions in:
Trying to fill text in input box with dynamic drop down
Need help to fill number into Chrome input box with Selenium
Try referring this webpage
The page you are trying to access has added a web element over another web element. i.e web element of id navbar_password_hint over web element of id navbar_password. Try referring above link to solve your problem.
This happens when the element state is not clickable. You have to use webdriver wait property and make sure that element state is clickable
WebDriverWait wait= new WebDriverWait(driver, 10);
WebElement e= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element")));
e.click();
I'd like to using protractor script to verify given password is hidden not in clear text. However
element.getAttribute('value')
returns the clear text.
My questions:
Is it possible to verify the hidden password with help of a protractor script?
If yes, what is the correct function or what are the correct
functions?
The main difference between a normal text field and password field is their type attribute. For normal text field, the value of type attribute is <input type='text'> and for password field <input type='password'>. So using protractor it can be verified using below code.
var passwordField = element(by.name("pass"));
expect(passwordField.getAttribute("type")).toEqual("password");
I'm using Capybara with Cucumber.
The webpage I'm testing contains many email fields throughout but the ID's and labels for the input field change depending on which page you're on.
What I'm trying to do is create an generic reference to any email field so that one fill in method will work for all pages.
When inspecting the input fields, I can see they are of type='email
The full html:
<input id="privatekeeper_email_email" name="privatekeeper_email.email" value="" data-validity-message="Must be a valid email address" no_optional_label="true" type="email" autocomplete="off" maxlength="254">
In my block below you should be able to grasp what I'm tring to do:
email_fields = all('input[type="email"]')
fill_in(email_fields[0], with: text)
fill_in(email_fields[1], with: text)
end
When I run this, I get the following error:
Capybara::ElementNotFound: Unable to find field #<Capybara::Node::Element tag="input" path="/html/body/div[3]/div/div[2]/form/div/div[2]/div[6]/div/div[2]/div/div/div/div[2]/input">
Reading the Capybara docs, I can see that fill_in responds to ID, name or Label so my reference might not work. Is there anyway I could get this block to work?
Like I said, the Id's and labels are not consistent throughout the user journey
Since you've already found the element you need to call #set on it instead of using fill_in
email_fields[0].set(text)
Using the POST HTTP method, Site Scanner found that :
The following resources may be vulnerable to cross-site scripting (extended patterns) :
The 'email' parameter of the /customer/account/forgotpasswordpost/ CGI :
/customer/account/forgotpasswordpost/ [email=508 src=http://www.example.
com/exploit508.js]
As far I see code, Magento senitize the _GET/_POST. How can I get fixed this?
I guess this will depend on what version of Magento you are running. The default location for the template in question can be found at app/design/frontend/base/default/template/customer/form/forgotpassword.phtml. The only value that is user editable that is echo'd out to the screen is the e-mail address, certainly in Magento 1.6 this is being passed through the template blocks htmlEscape method, but it's worth checking that it is in your version of Magento.
<input type="text" name="email" alt="email" id="email_address" class="input-text required-entry validate-email" value="<?php echo $this->htmlEscape($this->getEmailValue()) ?>" />
If you find that it already is then it would be worth checking that this template isn't being overloaded in your current theme.
How does form autofill work in modern web browsers? Which are the most common techniques used in browsers that implement automatic form filling?
-- EDIT --
The question is not about autocomplete, is about form autofilling, which cares not only about the previously inputted values but also considers the meaning and structure of the field to be completed. Google Chrome implementation, for example, tries to parse the inputted fields to guess their type and structure. Or at least is that what I understood from the code linked above.
Take a look over at this answer by kmote.
Highlight is that the browser looks at the field's name tag and makes an educated guess at what sort of data would go there (regex matching is a good naive way to do this). Chrome is working to get some sort of standardization so that this isn't quite as hit-or-miss.
Different technologies and browsers use various methods to both calculate what to display as well as how they display it, but some sources to check out are:
Google's high-level description
How to implement it with jQuery (note that there is a jQuery autocomplete plugin as well).
If you are looking into implementing it (or just using it) yourself, I would highly recommend taking a look at the plugin.
The first element of answer is simply the non standard HTML form's autocomplete attribute that was introduced with Internet Explorer a few years ago.
Ironically, you can read a good history an introduction on mozilla site here: The autocomplete attribute and web documents using XHTML
This question is pretty old but I have an updated answer for 2017!
In order to trigger autocomplete, all you have to do is name it right.
The following answer is from my original answer from here: https://stackoverflow.com/a/41965106/1696153
Here's a link to the official current WHATWG HTML Standard for enabling autocomplete.
Google wrote a pretty nice guide for developing web applications that are friendly for mobile devices. They have a section on how to name the inputs on forms to easily use auto-fill. Eventhough it's written for mobile, this applies for both desktop and mobile!
How to Enable AutoComplete on your HTML forms
Here are some key points on how to enable autocomplete:
Use a <label> for all your <input> fields
Add a autocomplete attribute to your <input> tags and fill it in using this guide.
Name your name and autocomplete attributes correctly for all <input> tags
Example:
<label for="frmNameA">Name</label>
<input type="text" name="name" id="frmNameA"
placeholder="Full name" required autocomplete="name">
<label for="frmEmailA">Email</label>
<input type="email" name="email" id="frmEmailA"
placeholder="name#example.com" required autocomplete="email">
<!-- note that "emailC" will not be autocompleted -->
<label for="frmEmailC">Confirm Email</label>
<input type="email" name="emailC" id="frmEmailC"
placeholder="name#example.com" required autocomplete="email">
<label for="frmPhoneNumA">Phone</label>
<input type="tel" name="phone" id="frmPhoneNumA"
placeholder="+1-555-555-1212" required autocomplete="tel">
How to name your <input> tags
In order to trigger autocomplete, make sure you correctly name the name and autocomplete attributes in your <input> tags. This will automatically allow for autocomplete on forms. Make sure also to have a <label>! This information can also be found here.
Here's how to name your inputs:
Name
Use any of these for name: name fname mname lname
Use any of these for autocomplete:
name (for full name)
given-name (for first name)
additional-name (for middle name)
family-name (for last name)
Example: <input type="text" name="fname" autocomplete="given-name">
Email
Use any of these for name: email
Use any of these for autocomplete: email
Example: <input type="text" name="email" autocomplete="email">
Address
Use any of these for name: address city region province state zip zip2 postal country
Use any of these for autocomplete:
For one address input:
street-address
For two address inputs:
address-line1
address-line2
address-level1 (state or province)
address-level2 (city)
postal-code (zip code)
country
Phone
Use any of these for name: phone mobile country-code area-code exchange suffix ext
Use any of these for autocomplete: tel
Credit Card
Use any of these for name: ccname cardnumber cvc ccmonth ccyear exp-date card-type
Use any of these for autocomplete:
cc-name
cc-number
cc-csc
cc-exp-month
cc-exp-year
cc-exp
cc-type
Usernames
Use any of these for name: username
Use any of these for autocomplete: username
Passwords
Use any of these for name: password
Use any of these for autocomplete:
current-password (for sign-in forms)
new-password (for sign-up and password-change forms)
Resources
Current WHATWG HTML Standard for autocomplete.
"Create Amazing Forms" from Google. Seems to be updated almost daily. Excellent read.
"Help Users Checkout Faster with Autofill" from Google in 2015.