![](/img/trans.png)
[英]How to handle javascript error in phantomjs selenium with java?
[英]Handle javascript in selenium ide
以下是我未能成功點擊提交按鈕的示例:
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)
在進行geralert
之前,您可以嘗試通過selenium.setSpeed("5000")
設置速度。
也許這不是機敏。 也許是確認。 您是否嘗試過selenium.getConfirmation();
這里有一些更多的信息。
selenium.click("link=Ask Expert");
Thread.sleep(5000);
assertEquals("Thank You ! Someone from Career Fundas experts panel will contact you shortly.", selenium.getAlert());
使用此代碼,它在我的工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.