【问题标题】:Handle javascript in selenium ide在 selenium ide 中处理 javascript
【发布时间】:2013-03-28 05:23:00
【问题描述】:

以下是我点击提交按钮失败的示例:

package demo;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class leadtest 
        {
    private Selenium selenium;
    private SeleniumServer server;

    @Before
    public void setUp() throws Exception 
                {
        server = new SeleniumServer();
        server.start();
        selenium = new DefaultSelenium("localhost", 4444, "*firefox",
            "http://www.careerfundas.com/");
        selenium.start();
            }

    @Test
   public void testLeadtest() throws Exception
                {
        selenium.open("/");
        selenium.click("id=wrapper");
        selenium.click("css=a.active-home > span");
        selenium.waitForPageToLoad("30000");
        selenium.click("id=wrapper");
        selenium.click("css=li");
        selenium.waitForPageToLoad("30000");
        selenium.click("id=confused_name");
        selenium.type("id=confused_name", "Shalini test");
        selenium.type("id=confused_email", "Shalinitest@test.com");
        selenium.type("id=confused_phoneno", "9090909090");
        selenium.select("id=conf_course", "label=Shipping and Logistics");
        selenium.click("link=Ask Expert");
        assertEquals(
            "Thank You ! Someone from Career Fundas experts panel will    contact you shortly.", selenium.getAlert());


            }



    @After
    public void tearDown() throws Exception 
       {
        selenium.stop();
   }

      }  

注意: 以下是我尝试在 java 脚本之上运行时遇到的错误。

com.thoughtworks.selenium.SeleniumException: ERROR: There were no alerts
at com.thoughtworks.selenium.HttpCommandProcessor.
throwAssertionFailureExceptionOrError (HttpCommandProcessor.java:112)

【问题讨论】:

  • 可能是服务器在执行getAlert()命令的时候没有显示alert。尝试在断言语句之前添加selenium.waitforpagetoload(30000); 并检查行为。如果您仍然面临问题。让我们知道。

标签: java javascript eclipse selenium selenium-ide


【解决方案1】:
  1. 您可以先尝试通过selenium.setSpeed("5000") 设置速度 做一个geralert

  2. 也许它没有警觉。也许是确认。 你试过selenium.getConfirmation();

Here 是一些关于它的更多信息。

【讨论】:

    【解决方案2】:
    selenium.click("link=Ask Expert");
    Thread.sleep(5000);
    assertEquals("Thank You ! Someone from Career Fundas experts panel will contact you shortly.", selenium.getAlert());
    

    使用此代码,它在我的最后工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2013-01-23
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多