Wednesday 15 January 2014

c# - why the modal window doesn't show up when clicked by selenium -



c# - why the modal window doesn't show up when clicked by selenium -

i seek click on login button(Đăng nhập) show login box, fail accomplish it.

the loginbox doesn't show up.

selenium, webdriver latest version

using (iwebdriver driver = new chromedriver()) { driver.navigate().gotourl("http://sinhvienit.net/forum/"); // driver.manage().timeouts().implicitlywait(timespan.fromseconds(30)); // driver.findelement(by.xpath("//a[@href='#loginform']//span")).click(); // driver.findelement(by.xpath("//a[@href='#loginform']")).click(); var wait = new webdriverwait(driver, timespan.fromseconds(30)); wait.until(expectedconditions.elementexists(by.xpath("//a[@href='#loginform']"))).click(); wait.until(expectedconditions.elementexists(by.xpath("//a[@href='#loginform']//span"))).click(); wait.until(expectedconditions.elementexists(by.id("navbar_username"))); wait.until(expectedconditions.elementexists(by.id("navbar_password"))); // var loginbox= wait.until(elementisclickable(by.id("loginform"))); >> fail driver.scripts().executescript("document.getelementbyid('navbar_username').style.display='inline';"); driver.scripts().executescript("document.getelementbyid('navbar_password').style.display='inline';"); console.readkey(); }

c# extension:

public static ijavascriptexecutor scripts(this iwebdriver driver) { homecoming (ijavascriptexecutor)driver; }

there 2 problems.

1- there's webpage coming prior actual forum page, when navigating site. below image that:

so have click on button, highlighted above first. and, after able navigate forum's page.

2- button getting clicked, since webpage has not loaded, click action not proceeding.

hence, need wait element gets loaded when page loaded properly.

below code help out:-

using (iwebdriver driver = new chromedriver()) { driver.navigate().gotourl("http://sinhvienit.net/forum/"); driver.manage().timeouts().implicitlywait(timespan.fromseconds(30)); //give implicit wait time driver.findelement(by.xpath("//button[@id='btnsubmit1']")).click();// clicking on button nowadays in prior page of forum //waiting till element marks page loaded properly, visible var wait = new webdriverwait(driver, timespan.fromseconds(30)); wait.until(expectedconditions.expectedconditions.elementisvisible(by.xpath("//*[@id='vtlai_topx']/a"))); driver.findelement(by.xpath("//a[@href='#loginform']")).click();

...

you can proceed rest then.

c# selenium selenium-webdriver

No comments:

Post a Comment