eclipse - Java Selenium webdriver code not execute ;Password Field remains Empty -
i seek execute java webdriver code ,selenium test login page .i passed input excel correctly assign values username , password .once click login button -
till login button submit works perfectly. if 1 time login button clicked.. password field in page remain empty , login effort failed cant sort out problem. thank reply , appreciate
package exceltest; import java.io.file; import java.io.fileinputstream; import org.apache.poi.xssf.usermodel.xssfcell; import org.apache.poi.xssf.usermodel.xssfrow; import org.apache.poi.xssf.usermodel.xssfsheet; import org.apache.poi.xssf.usermodel.xssfworkbook; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.firefox.firefoxdriver; public class sample { public static void main( string[] args) throws exception { string [][] data; info = excelread(); string expectedtitle; (int = 1; < data.length; i++ ) { expectedtitle = login(data[i][0],data[i][1]); system.out.println("page title after login is" + expectedtitle ); if(expectedtitle.equalsignorecase("homepage title")) { system.out.println("passed"); } else{ system.out.println("failed"); } } } public static string login(string username,string password) throws interruptedexception { webdriver driver = new firefoxdriver(); driver.get("http://localhost/xxx/default.aspx"); thread.sleep(1000); //driver.findelement(by.id("loginusername")).clear(); driver.findelement(by.id("loginusername")).sendkeys(username); //driver.findelement(by.id("loginpassword")).clear(); driver.findelement(by.id("loginpassword")).sendkeys(password); driver.findelement(by.id("loginloginbutton")).click(); thread.sleep(1000); string expectedtitle = driver.gettitle(); homecoming expectedtitle; } public static string [][] excelread()throws exception { file excel = new file("d:\\book1.xlsx"); fileinputstream fis = new fileinputstream(excel); xssfworkbook wb = new xssfworkbook(fis); xssfsheet ws = wb.getsheet("sheet1"); int totrow = ws.getlastrownum()+ 1; int totcol = ws.getrow(0).getlastcellnum(); string [][] info = new string[totrow][totcol]; (int = 0 ; < totrow ; i++) { xssfrow row = ws.getrow(i); (int j=0 ; j < totcol ; j++){ xssfcell cell = row.getcell(j); string value = celltostring(cell); data[i][j] = value; system.out.println("the value " + value); } } homecoming data; } public static string celltostring(xssfcell cell) { int type; object result ; type = cell.getcelltype(); switch (type) { case 0 : result = cell.getnumericcellvalue(); break; case 1 : result = cell.getstringcellvalue(); break; default : throw new runtimeexception("there no back upwards type of cell"); } homecoming result.tostring(); } }
you not using same locator (class 'by') clearing password field , come in passsword. sure both locators correct? password filed empty because not selecting right element. must select input tag of html.
other remarks. shouldn't utilize thread.sleep() create test case works, have race condition. should maintain reference elements. calling findelement everytime useless , create test slow.
webelement e = driver.findelement(by.id("whatever")); e.clear(); e.sendkeys(...); java eclipse excel selenium-webdriver apache-poi
No comments:
Post a Comment