A WebElement is anything you see on a web page such buttons, text fields, links, etc.
There are 8 Selenium Locators that help us find WebElements. In alphabetical order, the Selenium Locators are
1. className
2. cssSelector
3. id
4. linkText
5. name
6. partialLinkText
7. tagName
8. xpath
This video shows how to use 6 of the 8 Selenium Locators. A separate video will demo cssSelector and xpath.
► Download Transcript, Presentation, and Code https://www.rexjones2.com/select-webe...
► View/Download Transcript, Presentation, and Code via GitHub https://github.com/RexJonesII/Seleniu...
All Selenium Locators via Free Selenium Book (pages 54 - 108)
► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books
► Java PDF Book: http://tinyurl.com/Part-1-Java-4-Sele...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books
► View All Videos On LinkedIn / admin
► View All Videos On YouTube / @rexjonesii
► View All Videos On Facebook https://www.facebook.com/pg/Selenium-...
► Transcript
Hello and Welcome To Selenium 4 Beginners. We are going to discuss How To Use Selenium Locators To Find WebElements. The Transcript, Presentation, and Code will be available on github at RexJonesII/Selenium4Beginners and https://tinyurl.com/SeleniumLocatorsF....
Before checking out How To Use A Selenium Locator To Find A WebElement, let’s look at the Selenium Locators then at the end we are going to look at the rankings for the Selenium Locators.
In alphabetical order, the 8 Selenium Locators are className, cssSelector, id, linkText, name, partialLinkText, tagName, and xpath. Now, let’s look at the Selenium Locators that help us find WebElements.
I believe finding a WebElement is the most important aspect of automation. Why? because we are unable to perform any action on a WebElement until we first find the WebElement.
I have already created an instance of WebDriver, a setup method to load OrangeHRM, and our Test Method called demoSeleniumLocators. Recall from the previous video, I mentioned id, name, and class are the key attributes for finding WebElements. Therefore, I will start with id which is a unique identifier for an element. We write driver.findElement By then the dot operator. Here’s a list of all 8 Selenium Locators, select id, (pause) and the parameter is the value of id attribute. Let’s go to the AUT and find the value of id by inspecting username.
The value is txtUsername. Copy the value and paste the value. WebElement username = We are not going to perform actions on the WebElement but only find the WebElement. As a result, I will demonstrate finding the WebElement by highlighting each WebElement. Highlighter.highlightElement pass in the driver and pass in username as the WebElement.
This is a static highlighter method so I can call it directly from the utility package. The background will be red with a black border. Highlighter methods are good for demos because it can slow down execution. This execution will slow down for 1 second due to Thread.sleep 1000. Let’s run. Did you see Username highlight red? That shows we successfully found Username. We are going to do that for each WebElement.
driver.findElement By dot name and the parameter is the value of name attribute
Next, is the Password field. The name attribute has a value of txtPassword. Copy and Paste the value. WebElement password = Highlighter.highlightElement pass in the driver and password. Let’s run again then see username and password highlight red.
driver.findElement By dot className and the description shows Find elements based on the value of the class attribute. Inspect button. The class attribute has a value of button. Copy and Paste the value. WebElement buttonLogin = Highlighter.highlightElement pass in the driver and buttonLogin. Let’s Run. We saw all 3 WebElements show a red background.
The next 2 Selenium Locators help find links on a web page: linkText and partialLinkText driver.findElement By dot linkText and parameter is the exact text to match against
driver.findElement By dot partialLinkText finds part of the text.
Let’s use Forgot your password for linkText and OrangeHRM, Inc for partialLinkText. Inspect both WebElements. Here’s the text for Forgot your password and OrangeHRM. WebElement linkForgotPassword = Highlighter.highlightElement pass in driver and linkForgotPassword
The value for Partial Link Text will be OrangeHRM. WebElement linkOrangeHRM = Highlighter.highlightElement pass in driver and linkOrangeHRM. Let’s scroll down the page
#SeleniumTraining #SeleniumAutomation #BeginnerSeleniumTutorials #SeleniumWebDriver
Смотрите видео ✔ How To Use Selenium Locators To Find WebElements | (Video 41) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Rex Jones II 06 Июнь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 708 раз и оно понравилось 7 людям.