Saturday 29 August 2015

3. Locating elements

3. Locating elements


0.  $ and $$

1. Locating element by id

2. Locating element by css selector

3. Locating element by xpath selector

4. Locating element by class name

5. Locating element by name

6. Locating element by tag name

7. Locating element by link text

8. Locating element by partial link text

9. Locating element by text

10. Locating element with text

11. Locating element by title

12. Locating element by attribute

13. Locating element by value 

14. Locating one element in another element by chain


0. $ and $$


Use "$" to find one element:
$("#someId")  is the same as driver.findElement(By.id("someId"))

Use "$$" to find all elements:
$$(".someCssSelector") is the same as driver.findElements(By.cssSelector("someCssSelector"))


1. Locating element by id


$("#someId");
$(By.id("someId"));

2. Locating element by css selector


$(".someCssSelector");
$(By.cssSelector(".someCssSelector"));


3. Locating element by xpath selector


$(By.xpath(".//*[@class='price']"));

4. Locating element by class name


$(By.className("nav"));



5. Locating element by name


$(By.className("someName"));


6. Locating element by tag name


$(By.tagName("a"));


7. Locating element by link text


$(By.linkText("Logout"));


8. Locating element by partial link text


$(By.partialLinkText("out"));


9. Locating element by exact text


$(byText("Logout")); 


10. Locating element with text  (substring)


$(withText("out")); 
    


11. Locating element by title attribute


$(byTitle("someTitle")); 


12. Locating element by attribute


$(byAttribute("class", "g")); 



13. Locating element by value attribute 


$(byValue("someValue"));

          

14. Locating one element in another element by chain


$("#mainElement").$("#subElement")



Source: Selenide Cheat Sheet

2 comments:

  1. Hello Saga
    Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.
    When I started learning then I understood it has got really cool stuff.
    I can vouch webdriver has proved the best feature in
    Selenium framework.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete