Pages

[Web Automation] - How to simulate click any buttons from any websites?

In the previous tutorial explain how the web automation work and how you can use it. In this tutorial will guide you how to simulate click any buttons, any links from any website easily.




The click function using xpath parameter to click to the element, so if you have the xpath just write the code as below:

click('xpath');

Basically, when you execute this function the code will get the xpath you provide and find the element then it will execute actual click to this element.

For example, I go to the website http://www.google.com.vn, I enter "test" for keyword and then right click to the button "Tìm với Google", this will get the xpath of this button and show the function in the developer tool.


This is the result when you choose "Click" and select "Element"


Click Run you will see browser will navigate you to search the "test" keyword in google


By using this tool, you can simulate click on any element such as: link, button,... in any website. I will show you how to navigate to the website and click to link automatically.

Use this code to navigate to website "New York Times", wait exactly 15 seconds before click to the politics category on this site:

go('https://www.nytimes.com/');
sleep(15, false);
click("//*[@id='mini-navigation']/ul[1]/li[5]/a[1]");


Next tutorial, I will show you how to simulate file upload by using web automation tool.

No comments:

Post a Comment