Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Need help on following scenario(using Java):

Doing it manually like this: after filling in some info in a parent page, clicking Continue button on it,

<INPUT TYPE='button' VALUE='Continue' onClick='sendForm()'>

A child window(UserConfirmationPage) pops up with those info from its parent window, clicking the Continue button on the child page, posting the data to server.

<FORM NAME='userConf' ACTION='user.jsp' METHOD='post'> 
Do you want to continue?<BR>
<INPUT TYPE='button' VALUE='Continue' onClick='createUser()'> 
</FORM>

However, when I do it using Selenium Web Driver, on the parent page,

btnContinue.submit() 

a child page pops up with those info from parent page just like what I got when I do it manually but parent does not exist any more. While using

btnContinue.click() 

a blank child page is opened without getting any info from parent page and it also complains "session is lost".

I also tried:

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].click();",btnContinue);

and

 new Actions(driver).moveToElement(driver.findElement(By.xpath("//input[@value='Continue']"))).click().perform();

but nothing works.

It seems that neither Submit() nor Click() could simulate what was done manually. Any idea?

Thanks a lot in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
151 views
Welcome To Ask or Share your Answers For Others

1 Answer

You did not specify the language, so I assume you're using JAVA:

// since new tab has been opened - need to switch to this tab
// get a list of the currently open windows
Set<String> allTabs = driver.getWindowHandles();

// save the window handle for the current window
String programTab = driver.getWindowHandle();

// switching to the Save tab
String saveTab = ((String) allTabs.toArray()[1]);
driver.switchTo().window(saveTab);
// set timeout

// Click button
driver.findElement(By.id("buttonId")).click();
// set timeout

// switch back to the program tab
driver.switchTo().window(programTab);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...