Sunday 15 January 2012

java - test not working in ChromeDriver but working fine in FirefoxDriver -



java - test not working in ChromeDriver but working fine in FirefoxDriver -

i trying test website on chromdriver. goes welcome page won't respond. not getting exception code not doing anything. same code working firefoxdriver without code change.

java code ---->>

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 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 username try{ wb=driver.findelement(by.id("bodycontent:txtusername")); wb.click(); wb.sendkeys("shantanunandan@gmail.com"); }catch(nosuchelementexception e){ wb=driver.findelement(by.xpath(".//*[@id='bodycontent:txtusername']")); wb.click(); wb.sendkeys("shantanunandan@gmail.com"); }//catch //entering 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 wrong try{ wb=driver.findelement(by.classname("txt_red")); string error = wb.gettext(); string expected="please recheck, username/e-mail id/password incorrect. remember can login e-mail id. (please check if box ticked in case e-mail id selected)"; if(expected.length()==error.length()){ system.out.println(error); driver.close(); }//if }catch(nosuchelementexception e){ }//catch **//closing 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

the above code wont works after goes //closing pop seek grab block

it might worthwhile trying out driver.switchto().window(driver.windowhandles.last()); if not other flavor driver.switchto().window("<window name>");

this seems case of window want click close button on not getting focussed.

java google-chrome google-chrome-extension selenium-webdriver webdriver

No comments:

Post a Comment