Selenium webdriver Learn, select module, click Next page, get current URL
Find the next page there are several methods, here are listed two kinds;
The isSelected () function is used to determine whether a click is selected to return a Boolean type
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import Org.openqa.selenium.chrome.ChromeDriver;
Import java.util.List;
Import com.thoughtworks.selenium.Wait.WaitTimedOutException;
public class ysftest_20180720 {
Main method
public static void Main (string[] args) throws interruptedexception{
Load Drive
System.setproperty ("Webdriver.chrome.driver", "C:/Program Files (x86)/google/chrome/application/chromedriver.exe" );
Open your browser
Webdriver Driver = new Chromedriver ();
Open Web site
Driver.get ("https://edu.csdn.net/");
Select the module, Linktext is the link text, we can find the element by Linktext
Webelement searchbox = driver.findelement (By.linktext ("course"));
Click the module
Searchbox.click ();
Select the next page module, locate the element by CSS selector, find the next page button
Webelement Searchnext = driver.findelement (By.cssselector ("a[class= ' btn btn-xs ' Btn-default ']");
Find the second way to do the next page
Webelement Searchnext = driver.findelement (By.cssselector (". Btn.btn-xs.btn-default.btn-next"));
Check if the element is selected and if it is not selected, click to select
if (!searchnext.isselected ()) {
Turn One page
Searchnext.click ();
}
Wait 5s
Thread.Sleep (5000);
Go to current URL
String Current_url = Driver.getcurrenturl ();
System.out.println (Current_url);
Close window
Driver.close ();
}
}
Selenium webdriver Learn, select module, click Next page, get current URL