javascript - Press Enter in popup using selenium - Stack Overflow

I m using Selenium to test my web application.Here I want to click the enter button to select the value

I m using Selenium to test my web application.

Here I want to click the enter button to select the values in list box. I have tried maximum all methods using javascript, sendkeys and Robot also. Everything is working fine in normal window, but when the popup appeared that time not working for this.

Has anyone faced this issue?

Kindly help me.

Thanks for advance.

I m using Selenium to test my web application.

Here I want to click the enter button to select the values in list box. I have tried maximum all methods using javascript, sendkeys and Robot also. Everything is working fine in normal window, but when the popup appeared that time not working for this.

Has anyone faced this issue?

Kindly help me.

Thanks for advance.

Share Improve this question edited Jun 5, 2020 at 13:18 Shubham Jain 17.6k16 gold badges87 silver badges134 bronze badges asked Aug 30, 2017 at 5:47 AkalyvanAkalyvan 1571 gold badge2 silver badges14 bronze badges 1
  • Consider sharing your code block and the relevant HTML. – undetected Selenium Commented Aug 30, 2017 at 6:13
Add a ment  | 

3 Answers 3

Reset to default 4

You need to switch the pop-up first and then you can perfrom action

Alert alertOK = driver.switchTo().alert();
alertOK.accept();

If the pop-up is not confirmation box then you need to switch and perform click operation

driver.switchTo().alert();
element.click();

OR If it is application pop-up then you can try below code

To switch to a popup window, you need to use getWindowHandles() and iterate through them.

In your code you are using getWindowHandle() which will give you the parent window itself.

String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String subWindowHandler = null;

Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window

// Now you are in the popup window, perform necessary actions here

driver.switchTo().window(parentWindowHandler);  // switch back to parent window

Hope it will help you :)

Try this code to switch the windows:

WebDriver driver = new FirefoxDriver();
driver.get("http://demo.guru99./popup.php");
driver.manage().window().maximize();
driver.findElement(By.xpath("html/body/p/a")).click();

// return the parent window name as a String
String parentWindow=driver.getWindowHandle();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Pass a window handle to the other window
for(String childWindow: driver.getWindowHandles())
{
if(!childWindow.equals(parentWindow)){
System.out.println("child");
//switch to child window
driver.switchTo().window(childWindow);
//find an element and print text of it 
WebElement textLabel=driver.findElement(By.xpath("html/body/div[1]/h2"));
System.out.println(" text:  "+textLabel.getText());
driver.close();
}
}
System.out.println("Come to parent window");
/switch to Parent window
 driver.switchTo().window(parentWindow);

Try the below code:

driver.switchTo().activeElement();

it's also working fine for me....

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745253568a4618822.html

相关推荐

  • javascript - Press Enter in popup using selenium - Stack Overflow

    I m using Selenium to test my web application.Here I want to click the enter button to select the value

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信