0
我想在ChromDriver上測試一個網站。當它進入歡迎頁面時,它不會迴應。我沒有得到任何異常,但代碼沒有做任何事情。在沒有任何代碼更改的情況下,相同的代碼適用於FirefoxDriver。測試不工作在ChromeDriver中,但在FirefoxDriver中正常工作
Java代碼的---- >>
public class Screen_1_Monster {
WebDriver driver;
WebElement wb;
public void operation() throws InterruptedException,NoSuchElementException{
String lastUpdate, update;
try{
// driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver","D:\\New Folder\\chromedriver.exe");
//WebDriver driver = new FirefoxDriver();
driver = new ChromeDriver();
//going to the desired website
driver.get("https://my.monsterindia.com/login.html?src=http://my.monsterindia.com/my_monster.html&rand=5257");
//maximize
driver.manage().window().maximize();
//wait
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
}catch(Exception e){
//Get status of Welcome page
driver.get("https://my.monsterindia.com/login.html?src=http://my.monsterindia.com/my_monster.html&rand=5257");
//maximize
driver.manage().window().maximize();
//wait
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
}//catch
//Entering the UserName
try{
wb=driver.findElement(By.id("BodyContent:txtUsername"));
wb.click();
wb.sendKeys("[email protected]");
}catch(NoSuchElementException e){
wb=driver.findElement(By.xpath(".//*[@id='BodyContent:txtUsername']"));
wb.click();
wb.sendKeys("[email protected]");
}//catch
//Entering the Password
try{
wb=driver.findElement(By.id("BodyContent_txtPassword"));
wb.click();
wb.sendKeys("ari2738");
}catch(NoSuchElementException e){
wb=driver.findElement(By.id(".//*[@id='BodyContent_txtPassword']"));
wb.click();
wb.sendKeys("ari2738");
}//catch
//Clicking on Login button
try{
driver.findElement(By.name("submit")).click();
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
}catch(NoSuchElementException e){
driver.findElement(By.xpath("//input[@name='submit']")).click();
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
}//catch
//if Usename/Password is incorrect
try{
wb=driver.findElement(By.className("txt_red"));
String error = wb.getText();
String expected="Please recheck, Username/E-mail id/Password is incorrect. Remember you can also login with your E-mail id. (Please check if the box is ticked in case e-mail id is selected)";
if(expected.length()==error.length()){
System.out.println(error);
driver.close();
}//if
}catch(NoSuchElementException e){
}//catch
**//Closing the pop up**
try{
driver.navigate().refresh();
driver.findElement(By.xpath("//*[@id='ProfileOverlay_close_other']")).click();
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
driver.findElement(By.className("flyout_close")).click();
driver.manage().timeouts().implicitlyWait(40 ,TimeUnit.SECONDS);
}catch(NoSuchElementException e){
}//catch
}//operation
public static void main(String args[]) throws InterruptedException {
Screen_1_Monster s = new Screen_1_Monster();
s.operation();
}
}//Screen_1_Monster
上面的代碼不會工作不言而喻//關閉彈出try catch塊
這是「彈出嘗試抓住」?此外,看起來你的嘗試/捕獲只是在第一次失敗時再次調用相同的動作。 – 2014-10-06 10:02:55
@Mark Rowlands就在主要方法之前。我評論它/ /關閉彈出 – 2014-10-06 10:30:34