Tuesday, April 1, 2025

 

๐—๐๐š๐ญ๐ก & ๐‚๐’๐’ ๐’๐ž๐ฅ๐ž๐œ๐ญ๐จ๐ซ ๐“๐ž๐œ๐ก๐ง๐ข๐ช๐ฎ๐ž๐ฌ ๐Ÿ๐จ๐ซ ๐€๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐“๐ž๐ฌ๐ญ๐ข๐ง๐ 

โ‡๏ธ XPath Functions & Axes

- `text()`โ€“ Matches elements based on exact text.
`//div[text()='login_id']`

- `normalize-space()`โ€“ Trims extra spaces before matching text.
`//div[normalize-space()='login test']`

- `contains()`โ€“ Finds elements containing a substring.
`//input[contains(@id, 'username')]`

- `starts-with()`โ€“ Selects elements whose attribute starts with a string.
`//button[starts-with(@class, 'btn')]`

- `position()`โ€“ Retrieves elements based on their position in a set.
`(//ul[@class='menu']/li)[position()=2]`

- `last()`โ€“ Selects the last element in a node set.
`(//table//tr)[last()]`

- `count()`โ€“ Counts the number of matching elements.
`count(//input[@type='checkbox'])`

- `ancestor::`โ€“ Finds all ancestors of an element.
`//a[text()='Logout']/ancestor::div`

- `following-sibling::`โ€“ Selects all following siblings.
`//label[text()='Email']/following-sibling::input`

- `parent::`โ€“ Selects the immediate parent element.
`//span[text()='Username']/parent::div`

- `descendant::`โ€“ Finds all descendants of an element.
`//div[@class='container']/descendant::input`

- `translate()`โ€“ Normalizes text by replacing or removing characters.
`//input[contains(translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'username')]`

โ‡๏ธ CSS Selector Techniques

- Tag & Attribute Selectorโ€“ Matches an element with a specific attribute.
`input[id='username']`

- Class Selectorโ€“ Matches elements with a specific class.
`.btn-primary`

- ID Selectorโ€“ Selects an element with a unique ID.
`hashtaglogin-button`

- Attribute Contains (`*=`)โ€“ Finds elements where an attribute contains a substring.
`input[id*='user']`

- Attribute Starts With (`^=`)โ€“ Matches elements where an attribute starts with a string.
`button[class^='btn']`

- Attribute Ends With (`$=`)โ€“ Matches elements where an attribute ends with a string.
`img[src$='.png']`

- Direct Child Selector (`>`)โ€“ Selects a direct child of an element.
`div > input`

- General Sibling Selector (`~`)โ€“ Selects all siblings after a specific element.
`label ~ input`

- Adjacent Sibling Selector (`+`)โ€“ Selects the immediate next sibling.
`label + input`

- Nth-Child Selector (`nth-child(n)`)โ€“ Selects the nth child of an element.
`ul.menu li:nth-child(2)`

- First & Last Child Selectorโ€“ Selects the first or last child of a parent element.
`ul.menu li:first-child`
`ul.menu li:last-child`

- Not Selector (`:not()`)โ€“ Excludes elements that match a certain condition.
`input:not([type='submit'])`


Related Posts:

  • What Is Hooks In Cucumber? What Is Hooks In Cucumber?Hooks is nothing but the script which run before or after each scenarios. There are some annotation which are used to execute script before or after each scenarioes.Below are the lists of cucumโ€ฆ Read More
  • What is BDD in selenium? What is BDD in selenium?BDD (Behavior Driven Development) is software development approach that allows developer or tester to create the script base on the behavior or functionality of the application.The steps of behavโ€ฆ Read More
  • โ‡๏ธBest Practices for Effective Selenium Automation โ‡๏ธBest Practices for Effective Selenium AutomationHereโ€™s a simplified list of best practices for Selenium automation:1. Use Explicit Waits - Avoid `Thread.sleep()`, use `WebDriverWait`.2. Page Object Model (POM) - Organโ€ฆ Read More
  • Test Runner class in BDD Test Runner classTest runner class is the starting point in BDD from where the script get executed with the help of junit annotation. Test runner class use junit class annotation which is @Runwith(). This gets execโ€ฆ Read More
  • Regular expression in step definition in cucumber Regular expression in step definitionBelow are some lists of special character that can be used while writing step definition.1. .(dot)-We can use any character in place of "." In below example, single step definitโ€ฆ Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

151,731

Blog Archive