c# - How to wait for element to load in selenium webdriver? -
i new selenium webdriver , testing 1 application. in application, have test linking facebook account. whenever click on link pop displayed have enter credentials. able link , test fails. know reason because takes time load pop window , next command executed not able find element. have used thread.sleep want use implicit wait or explicit wait practice rather thread.sleep. how use implicit wait , use command exactly? please advice. thanks.
public void socialfacebook() { string currentwindow = driver.currentwindowhandle; popupwindowfinder finder = new popupwindowfinder(driver); string facebookwindow = finder.click(driver.findelement(by.xpath("//div[@id='panelfacebook']/div[2]/div[3]/div[3]/a"))); // switch facebook window driver.switchto().window(facebookwindow); system.threading.thread.sleep(3000); // link // email address iwebelement facebooklinkemail = driver.findelement(by.id("email")); facebooklinkemail.sendkeys(socialfacebookemail); // password iwebelement facebooklinkpass = driver.findelement(by.id("pass")); facebooklinkpass.sendkeys(socialfacebookpass); // log in button iwebelement facebooklinklogin = driver.findelement(by.xpath("//input[@id='u_0_1']")); facebooklinklogin.click(); // switch main window driver.switchto().window(currentwindow); system.threading.thread.sleep(3000); // sync iwebelement facebooksync = driver.findelement(by.xpath("//div[@id='panelfacebook']/div[2]/div[3]/div[2]/a")); facebooksync.click(); // unlink iwebelement facebookunlink = driver.findelement(by.xpath("//div[@id='panelfacebook']/div[2]/div[3]/div[1]/a")); facebookunlink.click(); } sometimes not able find log in details pop not loaded , not able find sync button facebook account takes time link. please advice.
webdriverwait wait = new webdriverwait(driver, 30); wait.until(expectedconditions.visibilityofelementlocated(by.id("locator")));
it wait element located maximum of 30 seconds if element found before execute....
Comments
Post a Comment