WebElement Commands Tutorial doubt

Hi, first of all thanks to LAKSHAY SHARMA for making this useful tutorial.

I’m a manual tester and I want to transition to automation.

I’m at Webelement commands tutorial and I don’t understand the following line:

WebElement element = driver.findElement(By.id(“UserName“));

“UserName” is it supposed to be a element name on the dummy site?

There is no “UserName” field at http://store.demoqa.com/

Running class as it is results in exception.

Thanks in advance for you’re help

Default Asked on July 28, 2016 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi ,

    I have also learnt Selenium following the same blog. Let me try to explain.

    WebElement element = driver.findElement(By.id(“UserName“));

    Above, the code is trying to find an element on the web page which has an id ““UserName“.


    As a first step, kindly install FireBug and FirePath addons for Firefox.Ref. to http://toolsqa.com/selenium-webdriver/xpath-firebug-firepath/ for instructions on installing FireBug and FirePath

    1. Open Firefox browser and open the link “http://store.demoqa.com/” and click on “My Account”
    2. Now, open FireBug and click on the ARROW to inspect the “Username” field
    3. Click on the “Username” field on the web page

    It will hightlight the following :

    <input id=”log” class=”text” type=”text” tabindex=”1″ size=”20″ value=”” name=”log”/>

    If you observe, the “id” for the “Username” field is “log”.

    So in your code, if you wish to enter some data in the field “Username”, then your code will be as given below.

    WebElement element = driver.findElement(By.id(log));

    Hope this helps.

    Train Answered on August 9, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.