-2

Able to locate the elements in default content. but when I try to locate an element in javascript pop up, the webdriver hangs. i tried wait.until(ExpectedConditions), but no use. and i tried isDisplayed() as well. but still can't locate. Here's my coding:

WebElement LoginMbno=driver.findElement(By.xpath(".//*[@id='txtUserMobile']"));

if(LoginMbno.isDisplayed())
{
    System.out.println("Avialable");
}
else 
{
    System.out.println("Not");
}

LoginMbno.sendKeys(new String[]{"9944097094"});
WebElement LoginPwd=driver.findElement(By.xpath(".//*[@id='txtPassword']"));
LoginPwd.sendKeys(new String[]{"123456"});
WebElement LoginBtn=driver.findElement(By.xpath(".//*[@id='btnLogin']"));
LoginBtn.click();
4

4 回答 4

0

NOTE: I didn't correct the ids or something, just made clear Java out of it.

This is how your code should look like:

WebElement loginMbno=driver.findElement(By.id("txtUserMobile"));

if(loginMbno.isDisplayed()) {
    System.out.println("Available");
}else {
    System.out.println("Not");
}

LoginMbno.sendKeys("9944097094");
WebElement loginPwd=driver.findElement(By.id("txtPassword"));
loginPwd.sendKeys("123456");
WebElement loginBtn=driver.findElement(By.id("btnLogin"));
loginBtn.click();

Maybe you should learn some java basics before starting with different APIs

于 2013-06-07T15:12:22.647 回答
0

What you are referring to as a JavaScript popup is what is generally termed a lightbox. My guess as to why you are having problems is that it looks like the visibility of the field depends upon the setting of the radio button which seems to be remembered.

I would suggest the following:

WebElement signIn = driver.findElement(By.xpath("//a[.='User/Agent Sign In']")); 
signIn.click(); 
WebDriverWait wait = new WebDriverWait(driver, 15, 100); 
WebElement loginLightbox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("exestylepopup")));
WebElement userType = loginLightbox.findElement(By.id("rbtnLogin_0"));
userType.click(); 
WebElement mobile = loginLightbox.findElement(By.id("txtUserMobile")); 
WebElement password = loginLightbox.findElement(By.id("txtPassword"));

The code above is verbose so that you can see what is going on.

This code uses a WebDriver wait to find the element rather than using isDisplayed (isDisplayed will error if the element doesn't exist, the code I have supplied will not error and will wait until the element exists and is visible). I have also used the lightbox WebElement as the parent to search in when finding the elements in the light box, this should be slightly more performant than scanning the whole page.

于 2013-06-09T22:27:17.880 回答
0

after clicking loginBtn you could try driver.switchTo().activeElement() ; this helped me out of similar issue

于 2013-06-11T16:00:57.300 回答
0

Finally i've got the solution. The Reason why my webdriver couldn't locate the popup elements is, there was a Facebook plugin used in the webpage. so the webdriver was waiting for the response from www.facebook.com and no response from Facebook.com since it was blocked in my PC. now i unblocked facebook.com and everything is working fine. thanks to everyone who tried to help me out of this.

于 2013-06-12T05:47:52.813 回答