Find elements in interface Selenium

Hi there!

 

I am trying to build my first automated test script using Java and Selenium and after logig within my Appian Site, I would like to fill a simple form but I don't know how can I locate the different components (Textfield, Buttons, Dropdown,...).

 

Thank you so much!

  Discussion posts and replies are publicly visible

  • Hi danielh855 ,

    We have implemented automated test script using java and selenium but apart from this two you will have to configure Cucumber framework aswell in order to inspect the elements and different components.

    Please find below the two links which i think might help you:

     

    http://toolsqa.com/selenium-cucumber-framework/selenium-end-to-end-automation-test/

     

    http://www.seleniumframework.com/cucumber-jvm-3/find-element-strategies/

     

    Every HTML element in Selenium Java is of type “WebElement”

    A WebElement can be compared to an in-memory (DOM) object representation of HTML tag

    If the reference of driver is of type “Webdriver”, then we use the second syntax style, otherwise the first style. Both the styles work fine.

    To identify a tag (aka. web element) we might need any(multiple) of the following

    By.id

    By.name

    By.linkText

    By.partialLinkText

    By.className

    By.CssSelector

    By.tagName

    By.xpath

    Please find below some of the commands to identify the fields:

    Retrieve HTML of WebElement

    To retrieve the HTML of WebElement we print the attribute “outerHTML” for the element.

    To retrieve attributes, we use the method “getAttribute” on the WebElement. We will discuss all the options in the training class, but for now, this should give you enough idea how to retrieve different values out of a HTML tag [aka. WebElement in Selenium language]

    Let’s try to identify all elements on the above practiceselenium website and print its html.

    The steps are the same as described in the videos and description on “Browser Commands”

    Download and import the maven project into Eclipse – 

    How to download and import has been explained in detail in “Browser Commands” page video at the bottom

    There are two features “WebElements.feature” and “HtmlLocators.feature”

    Their corresponding step_definitions are in the files “WebElements.java” and “HtmlLocators.java” [Mapping 1-1 feature to step definition is not a good practice as per cucumber, but for now our focus is to learn selenium java api first, so we can refactor this code later]

    Cucumber Features

    WebElements.feature

    Feature: Demonstrating the usage of web elements

    Scenario: Identify text field and print its html

    When I open practiceselenium.com website

    Then I find first and last name and print the html

    Scenario: Identify link field and print its html

    When I open practiceselenium.com website

    Then I find menu and print the html

    Scenario: Identify button field and print its html

    When I open practiceselenium.com website

    Then I find button and print the html

    Scenario: Identify radio button and print its html

    When I open practiceselenium.com website

    Then I find radio button male and print the html

    Scenario: Identify checkbox and print html

    When I open practiceselenium.com website

    Then I find check box and print the html

    Scenario: Identify select list and print html

    When I open practiceselenium.com website

    Then I find select list and print html

    Scenario: Identify another select list and print html

    When I open practiceselenium.com website

    Then I find another select list and print html

    Scenario: Identify a div and print html

    When I open practiceselenium.com website

    Then I find div and print html

    Feature: Demonstrating the usage of web elements

    Scenario: Identify text field and print its html

    When I open practiceselenium.com website

    Then I find first and last name and print the html

    Scenario: Identify link field and print its html

    When I open practiceselenium.com website

    Then I find menu and print the html

    Scenario: Identify button field and print its html

    When I open practiceselenium.com website

    Then I find button and print the html

    Scenario: Identify radio button and print its html

    When I open practiceselenium.com website

    Then I find radio button male and print the html

    Scenario: Identify checkbox and print html

    When I open practiceselenium.com website

    Then I find check box and print the html

    Scenario: Identify select list and print html

    When I open practiceselenium.com website

    Then I find select list and print html

    Scenario: Identify another select list and print html

    When I open practiceselenium.com website

    Then I find another select list and print html

    Scenario: Identify a div and print html

    When I open practiceselenium.com website

    Then I find div and print html

    HtmlLocators.feature

    Feature: Use html locators

    Scenario: Identify html element

    When I login to practiceselenium website

    Then I access elements and use watir commands

    Feature: Use html locators

    Scenario: Identify html element

    When I login to practiceselenium website

    Then I access elements and use watir commands

  • Hello Shiva and arikd398,

    Thank you so much for your answers! I have seen that I could find the component ID using "inspector" tool from my browser and, with that, I can find the web element and use it within the code.