#To kill process by port:
npx kill-port 3000
Or
kill -9 $(sudo lsof -t -i:8080)
#To run ssh file
sh ./filename.sh
#To kill the pid by port
lsof -i :3000
kill -9 pid
To educate the beginners and make their life easy.
#To kill process by port:
npx kill-port 3000
Or
kill -9 $(sudo lsof -t -i:8080)
#To run ssh file
sh ./filename.sh
#To kill the pid by port
lsof -i :3000
kill -9 pid
When performing website automation testing, using the right locator strategy is critical for creating robust, maintainable, and reliable tests. Below is an overview of the most effective locator strategies in Selenium, Playwright, or other web automation tools:
Locators:
Id,
Xpath,
Css selector,
Name,
Class name,
Tag name,
Link text,
Partial link text
CSS Selectors constructing: By.cssSelector()
Note: If the class in tag contains multiple classes, just construct cssSelectors as by removing spaces and replace with dot.
Eg: By.cssSelector(“.classname1.classname2.classname3”)
By.cssSelector("tagname");
By.cssSelector("#id");
By.cssSelector(".classname");
By.cssSelector("tagname[attribute='value']");
Starts with: driver.findElement(By.cssSelector("a[href^='https']"));
Ends with: driver.findElement(By.cssSelector("img[src$='.png']"));
Contains: driver.findElement(By.cssSelector("input[name*='username']"));
Combining selectors:
Descendant selector: By.cssSelector("parent child"); driver.findElement(By.cssSelector("div form"));
Direct child: By.cssSelector("parent > child"); driver.findElement(By.cssSelector("ul > li"));
Multiple classes: By.cssSelector("tagname.class1.class2");
Grouping selector: By.cssSelector("selector1, selector2"); driver.findElement(By.cssSelector("button, input[type='submit']"));
Pseudo classes:
First child: By.cssSelector("parent :first-child"); driver.findElement(By.cssSelector("ul > li:first-child"));
Last child: By.cssSelector("parent :last-child"); driver.findElement(By.cssSelector("ul > li:last-child"));
Nth child: By.cssSelector("parent :nth-child(n)"); driver.findElement(By.cssSelector("table tr:nth-child(2)"));
Contains Text CSS Selectors do not have a direct equivalent to XPath’s contains(text(), 'value'). Use XPath in such cases.
Note: Use browser dev tools to verify your CSS selectors (document.querySelectorAll("cssSelector");).
Xpath constructing:
Xpath:
Absolute Xpath:
/html/body/header
Relative Xpath:
//header/div/button[1]
Relative Locators(selenium 4 and above):
Df
Synchronisation in Selenium:
Implicit Wait
Explicit Wait: WebDriverWait, Fluent Wait
Thread.sleep
Actions:
How to mouseover on object with selenium
Performing mouse and keyboard interactions with selenium
Contextclick(right click) on element
Double click on element
Drag and dropping the element
Frames:
#To kill process by port: npx kill-port 3000 Or kill -9 $(sudo lsof -t -i:8080) #To run ssh file sh ./filename.sh #To kill the pid by po...