Use Java+selenium to launch Chrome browser times wrong exception in thread "main" Org.openqa.selenium.NoSuchSession__JAVA_STUDY

Source: Internet
Author: User

Now many web content is dynamically generated, dynamic page information extraction can use selenium. To extract dynamic page information.

One way is to start the browser to execute the JS code, then the first step is to start the browser first.

The following code:

Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.chrome.ChromeDriver;

public class chrometest{public
	
	static void Main (string[] args) {
        system.setproperty ("Webdriver.chrome.driver "," D:\\chromedriver\\chromedriver_win32\\chromedriver.exe ");
      Create a new Webdriver object, but the new one is the chrome drive
        webdriver driver =new chromedriver (); 
      Opens the specified Web site
        driver.get ("http://www.baidu.com");
        System.out.println (Driver.gettitle ());

        /**
         * Dr.quit () and Dr.close () can exit the browser and simply say the difference: first
         Close, * If more than one page is open it is not clean, it only closes the current page. The second quit,
         * is out of all webdriver all the windows, back very clean, so recommend the use of quit most of the case exit method.
         * *
        driver.quit ()//Exit Browser
	}
}
The results of the operation are shown below:

The above results do not output "Baidu, you Know", so there are errors. I struggled with this mistake for a long time and finally solved it.

If you look closely, you can see a warning:the server did not provide any stacktrace that is reported in the above image information

In fact, the code here is not wrong, the cause of the error is that I use the Chromedriver version and the chrome version does not correspond.
The mapping relationship between the two can refer to this man's blog: http://blog.csdn.net/huilan_same/article/details/51896672

Then I downloaded a chromedriver that corresponds to my Chrome browser version and ran the code again as follows:


That's OK.


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.