如何在SQuery中使用JQuery在h3中创建.delay函数? [英] How can I make a .delay function in a h3 with JQuery in Selenium?

查看:116
本文介绍了如何在SQuery中使用JQuery在h3中创建.delay函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个包含两个'div'的'h3'点击,所以我试图做一个循环,通过它们,但它只打开第二个'div'。

I tried to made a click in an 'h3' that contains two 'divs' so I tried to make a loop to go through them but it only opens the second 'div'.

只要它打开两个'divs',当我发出警告,停止他们之间的应用程序。它的工作,但我想做,而不必阻止应用程序与警报,因为我在Eclipse的Java项目中使用它与Selenium。

Just it opens both 'divs' when I put an alert which stop the application between both of them. It works but I want to make this without have to block the application with the alert because I'm using it with Selenium in a Java project of Eclipse.

我试图使用 .delay()函数,但它不工作。我把这里使用的代码放在这里:

I tried to make this with a .delay() function but it didn't works. I put here the code that I use for it:

$("#proveDiv > div > h3").each(function(i, obj){
      $(obj).delay(60000).fadeIn().click();
})

它只打开第二个'div',但我想测试通过两个'divs',而不只是其中一个。

It only opens the second 'div', but I want to the test go through both 'divs' and not only on one of them.

我想知道是否有一些功能,如延迟或睡眠,执行此任务,但没有阻止应用程序。

I want to know if there is some function like delay or sleep that do this task but without blocking the application.

任何帮助谢谢。
非常感谢!

Any help would be appreciated. Thank you very much!

编辑:我也尝试了setTimeout函数,但是它没有工作。请让我知道我是否做错了。

I also tried with the function setTimeout but it didn't work also. Please let me know if I'm doing something wrong.

$("#proveDiv > div > h3").each( function(i) 
{
    setTimeout(function() 
    { 
       $(this).click()} , 10000)
    }  
)


推荐答案

假设你通过Selenium执行这个Javascript,测试它。
如何选择并逐个点击它们

Assuming you are executing this Javascript through Selenium and wants to test it. How about selecting and clicking them one by one

JavascriptExecutor driver = (JavascriptExecutor) webdriver;
driver.executeScript("$(`proveDiv > div > h3`).eq(0).click();");
TimeUnit.SECONDS.sleep(100); // or Thread.sleep(100);
driver.executeScript("$(`proveDiv > div > h3`).eq(1).click();");

这篇关于如何在SQuery中使用JQuery在h3中创建.delay函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆