简体   繁体   English

在Selenium IDE中处理JavaScript

[英]Handle javascript in selenium ide

Below is the example where i failed post clicking of submit button: 以下是我未能成功点击提交按钮的示例:

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();
   }

      }  

Note: Below is the error i am getting when i tried to run above java script. 注意:以下是我尝试在Java脚本上方运行时遇到的错误。

com.thoughtworks.selenium.SeleniumException: ERROR: There were no alerts
at com.thoughtworks.selenium.HttpCommandProcessor.
throwAssertionFailureExceptionOrError (HttpCommandProcessor.java:112)
  1. You may try setting the speed by selenium.setSpeed("5000") before you do a geralert . 在进行geralert之前,您可以尝试通过selenium.setSpeed("5000")设置速度。

  2. Maybe it is not alert. 也许这不是机敏。 Maybe it is confirmation. 也许是确认。 Did you try selenium.getConfirmation(); 您是否尝试过selenium.getConfirmation();

Here is some More information on it. 这里有一些更多的信息。

selenium.click("link=Ask Expert");
Thread.sleep(5000);
assertEquals("Thank You ! Someone from Career Fundas experts panel will contact you shortly.", selenium.getAlert());

Use this code, its working at my end 使用此代码,它在我的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM