Selenium locators
We will learn about selenium locators in this blog.
Utilizing locators, one can find a certain webpage element.
Example:
There are a username and password required when logging into a website. Therefore, you must pass the username and password values while automating. You must find the element for that. Selenium element locator techniques are crucial in these situations. There are a variety of locators, and we'll talk about them in this blog.
Visit Locator strategies | Selenium and 8 classic locators that are already embedded into selenium will be visible. You can use them to automate any website, as we'll see.
1) Class name:
Visit Freeguideex , the search link is in the upper right corner. We'll write code to make sure it is clicked. and to do that, we'll utilize a class name locator.
driver.findElement(By.className("search-expand-text")).click();
In the above code, we have used "findElement" method. Inside this method we have used "By" class and subclass "className". Inside this subclass we have passed the class-name value.
Right-click on search link and click on Inspect.
you'll find the element highlighted. Copy the unique class name from highlighted element and use it in the code as shown above.
driver.findElement(By.cssSelector("input[name='q']")).sendKeys("Selenium");
driver.findElement(By.cssSelector("input.className"));
driver.findElement(By.cssSelector("input#ID"));
driver.findElement(By.name("q")).submit();
driver.findElement(By.class).click();
driver.findElement(By.tagName("input"));
driver.findElement(By.LinkText("Login"));
driver.findElement(By.partialLinkText("Sign"));
driver.findElement(By.xpath("//div[@id='content']/input"));
.png)
Comments
Post a Comment