Selenium webdriver Learn, select module, click Next page, get current URL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.