简体   繁体   中英

Running test on Chrome Browser Testng

package org.testngsessions;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestRegist {
    public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver","C:\\Users\\Asus\\Desktop\\chromedriver.exe");
    WebDriver driver= new ChromeDriver();
    driver.get("http://automationpractice.com/");
    System.out.println(driver.getTitle());

    }
}

This code can not open google chrome. What am I doing wrong? In eclipse I get Only local connections are allowed.

Error :

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException:

将驱动程序版本更改为“ chromedriver-2.35”

I've downloaded latest 2.40 chrome driver and Your code worked for me.

So You probably have issue with driver or if using maven, try updating your client / server

//client //

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.12.0</version>
    </dependency>

//server//

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>  
        <artifactId>selenium-java</artifactId>
        <version>3.12.0</version>
    </dependency>

and check latest chrome driver here: http://chromedriver.chromium.org/

Hope this helps,

Title says: System.out.println(driver.getTitle()); "My Store" :)

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
WebDriver driver= new ChromeDriver(chromeOptions);

Use the chrome driver with "no-sandbox" option with above code.it will work. I hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM