2017-01-03 2 views
0

В настоящее время я пытаюсь перезапустить старый тест Selenium. Он работал так, как предполагалось ранее, но теперь, когда я пытаюсь запустить его, я получаю сообщение об ошибке. Вот следующий код:Автоматическое закрытие веб-браузера в Selenium

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

public class IMDBSearch { 

public static void main(String[] args) 
{ 
    //new driver for chrome 
    WebDriver driver = new ChromeDriver(); 
    //entering the url 
    String url = "http://www.imdb.com/search/title"; 
    driver.get(url); 
    //clicking the featured film radio button 
    WebElement featureFilm = driver.findElement(By.id("title_type-1")); 
    featureFilm.click(); 
    //clicking the tvmovie radio button 
    WebElement tvMovie = driver.findElement(By.id("title_type-2")); 
    tvMovie.click(); 
    //clicking the tv radio button 
    WebElement tvButton = driver.findElement(By.id("title_type-3")); 
    tvButton.click(); 
    //using the xpath to select a 7.0 minimum rating 
    WebElement userRating = driver.findElement(By.xpath("//body//div[@id='main']//div/select[@name='user_rating-min']/option[text()= '7.0']")); 
    userRating.click(); 
    //using xpath to select US as a country 
    WebElement country = driver.findElement(By.xpath("//body//div[@id='main']//div/select[@class = 'countries']/option[@value= 'us']")); 
    country.click(); 
    //using xpath to select the sorting by user rating 
    WebElement sort = driver.findElement(By.xpath("//body//div[@id= 'main']//div/select[@name = 'sort']/option[@value = 'user_rating,asc']")); 
    sort.click(); 
    //using xpath to click on the search button 
    WebElement searchButton = driver.findElement(By.xpath("//div[@id= 'main']/p/button[text()= 'Search']")); 
    searchButton.click(); 
    //using xpath to get the first movie from the list 
    //displaying the first movie from the list 
    WebElement firstTitle = driver.findElement(By.xpath("//div[@id = 'main']//h3/span[text()= '1.']/following-sibling::a")); 
    String title = firstTitle.getText(); 
    System.out.println("1. " + title); 
    //using xpath to get the second movie from the list 
    //displaying the second movie from the list 
    WebElement secondTitle = driver.findElement(By.xpath("//div[@id = 'main']//h3/span[text()= '2.']/following-sibling::a")); 
    String title2 = secondTitle.getText(); 
    System.out.println("2. " + title2); 
    //using xpath to get the third movie from the list 
    //displaying the third movie from the list 
    WebElement thirdTitle = driver.findElement(By.xpath("//div[@id = 'main']//h3/span[text()= '3.']/following-sibling::a")); 
    String title3 = thirdTitle.getText(); 
    System.out.println("3. " + title3); 
    //using xpath to get the fourth movie from the list 
    //displaying the fourth movie from the list 
    WebElement fourthTitle = driver.findElement(By.xpath("//div[@id = 'main']//h3/span[text()= '4.']/following-sibling::a")); 
    String title4 = fourthTitle.getText(); 
    System.out.println("4. " + title4); 
    //using xpath to get the fifth movie from the list 
    //displaying the fifth movie from the list 
    WebElement fifthTitle = driver.findElement(By.xpath("//div[@id = 'main']//h3/span[text()= '5.']/following-sibling::a")); 
    String title5 = fifthTitle.getText(); 
    System.out.println("5. " + title5); 

} 

В то время как я знаю, что это работает ранее, он стрелял мне эту ошибку:

Starting ChromeDriver 2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129)   on port 20969 
Only local connections are allowed. 
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException:  session not created exception 
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData": {"frameId":"3940.1","isDefault":true},"id":1,"name":"","origin":"://"} 
    (Session info: chrome=55.0.2883.87) 
    (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64)  (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 2.14 seconds 
Build info: version: '3.0.0-beta2', revision: '2aa21c1', time: '2016-08-02 15:03:28 -0700' 
System info: host: 'Qualitest-PC', ip: '192.168.2.106', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:683) 
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) 
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130) 
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143) 
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170) 
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159) 
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116) 
at PracticeClass.main(PracticeClass.java:10) 

ответ

0

Вы должны попробовать обновить свой chromedriver версию. Версия, которую вы используете (v2.23), указана только для v51-53, и вы используете Chrome 55. Попробуйте использовать последнюю версию хромированной решетки v2.27

+0

Я могу найти chomedriver v2.25 на seleniumhq.org, вы Думаете, это должно сработать? –

+0

Попробуйте здесь: https://chromedriver.storage.googleapis.com/index.html – Josh

+0

Последняя версия всегда отображается здесь https://sites.google.com/a/chromium.org/chromedriver/downloads –

Смежные вопросы