我有以下代码(使用它来测试我的网络应用上的过滤器/搜索): (不要过分担心我搜索的内容等等,我只是想在按下搜索后让浏览器正常工作):
// Store my words
String sWordOne = "HTML1";
String sWordTwo = "WONT2";
String sWordThree = "WONTWORK3";
// Add These Entries
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordOne, "I have added this to check spelling", "Questions Tab Spelling");
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordTwo, "I have added this to check spelling", "Questions Tab Spelling");
Business_Surveys_Survey.Surveys_AddIndividualSql(sWordThree, "I have added this to check spelling", "Questions Tab Spelling");
navigateToSurveysManageSurveys();
WebElement sSearchBtn = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_btnSearch"));
WebElement sSearchBoxText = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_txtSearchBox"));
String sExpectedMessage = "Displaying 3 Records";
String sDisplayingXRecords = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_upSurveysList")).getText().trim();
String sSurveysOne = sDisplayingXRecords.substring(0, 20);
assertThat(sSurveysOne, containsString(sExpectedMessage));
sSearchBoxText.sendKeys("<HTML>");
sSearchBtn.click();
sSearchBoxText.clear();
String sDisplayingXRecordsOne = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_upSurveysList")).getText().trim();
String sDisplayingSurveys = sDisplayingXRecordsOne.substring(0, 20);
String sExpectedMessageTwo = "Displaying 1 Record";
assertThat(sDisplayingSurveys, containsString(sExpectedMessageTwo));
Business_Surveys_Survey.Surveys_NukeSurveyListbox();
每次执行以下操作:
sSearchBoxText.sendKeys("<HTML>");
sSearchBtn.click();
它中断了,我无法通过webdriver与浏览器交谈:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
我想也许是因为我添加了一些HTML标签,但即使我搜索基本单词,结果相同。我已经尝试过在框中发送返回键并按下页面上的搜索按钮。
任何想法?我怀疑以下内容,
navigateToSurveysManageSurveys();
WebElement sSearchBtn = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_btnSearch"));
WebElement sSearchBoxText = driver.findElement(By.id("ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolderSurvey_txtSearchBox"));
如果可以,请你解释我做错了什么以及我应该如何更好地处理这个?
感谢您的时间