Thursday, March 28, 2024
HomeJavaTips on how to Carry out Proper-Click on utilizing Java in Selenium?

Tips on how to Carry out Proper-Click on utilizing Java in Selenium?


Whereas automating a web site for testing there may be all the time required to carry out some right-click or different person actions on the web page.  These person actions are one of the crucial generally used actions throughout automation, so selenium gives a technique to carry out these person actions by the Actions class.

Tips on how to Carry out Proper Click on utilizing Actions Class

When a person performs a proper click on utilizing the mouse on a selected component to carry out some actions is known as a proper click on. We’re day by day utilizing this person motion totally on File Explorer, For instance, to rename a file or delete a file we carry out right-click and choose an possibility.

Oracle Java Certification, Oracle Java Prep, Java Tutorial and Materials, Oracle Java Material, Oracle Java Selenium

Proper Click on in Selenium

Let’s see how you can carry out the appropriate click on utilizing Selenium. Selenium Webdriver API doesn’t assist the person’s actions like Mouse hover, right-click, context-click, and double-click. That’s the place the Actions class got here to make use of, The actions supplied by this class are carried out by an API referred to as Superior person interplay in selenium webdriver.

Motion class current within the bundle,

“org.openqa.selenium.interactions bundle”

Let’s see how you can use the Actions class to Proper Click on a component:

Instantiate an object for the Actions class 

Actions motion = new Actions(driver);

After creating the article we’ve to find the net component

WebElement component=driver.findElement(locator);

Utilizing the “ContextClick() technique” from the Actions class to carry out the Proper click on. Context Click on strategies navigate the mouse pointer to the center of the net Factor after which carry out the right-click motion in that internet component.

motion.contextClick(webElement).carry out();

Instance

On this instance, we’re navigating to the URL “https://demoqa.com/buttons” and performing the Proper click on on the “Proper click on” button. 

public class Java {

public void oraclejavacertified()

{

ChromeDriver driver = new ChromeDriver();

driver.handle().window().maximize();

driver.get(“https://demoqa.com/buttons”);

WebElement component

= driver.findElement(By.id(“rightClickBtn”));

Actions motion = new Actions(driver);

motion.contextClick(component).carry out();

Thread.sleep(5000);

driver.shut();

}

Code Rationalization

Initially, we opened the browser and navigated to the URL

ChromeDriver driver = new ChromeDriver();

driver.handle().window().maximize();

driver.get(“https://demoqa.com/buttons”);

After that, we find the net component the place we’ve to carry out the “Proper Click on”. Then, We initialize the Motion class and carried out “Proper click on” on the net component.

 Actions motion=new Actions(driver);

 motion.contextClick(component).carry out();

Output

    

Proper-click is carried out and the consequence might be displayed.

Oracle Java Certification, Oracle Java Prep, Java Tutorial and Materials, Oracle Java Material, Oracle Java Selenium

Supply: geeksforgeeks.org

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments