如果我运行该文件的HTML版本,它在慢速模式下工作(但在快速模式下失败)。
我尝试在java中使用setspeed方法,但这不起作用(可能是因为它在以后的版本中被折旧了)。然后我尝试添加手动线程权重时间(在失败的点之前),但它也失败了。
不管怎样,下面是我的java代码:
import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.SeleneseTestBase;
public class tradePagesNotLoad extends SeleneseTestBase{
private Selenium selenium;
@Before
public void setUp() throws Exception {
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://www.fsdafdscsa.com/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}
@Test
public void testA9() throws Exception {
selenium.open("");
selenium.click("link=Sign In");
selenium.waitForPageToLoad("30000");
selenium.type("id=login_username", "fsadfsa");
selenium.type("id=login_password", "asweqr");
selenium.click("name=login_button");
selenium.waitForPageToLoad("30000");
verifyTrue(selenium.isElementPresent("link=Sign Out"));
selenium.click("link=Trade");
selenium.waitForPageToLoad("30000");
String sellButtonText = selenium.getText("xpath=(//button[@type='button'])[7]");
System.out.println(sellButtonText);
assertNotEquals("Loading...", selenium.getEval("storedVars['sellButtonText']"));
String buyButtonText = selenium.getText("xpath=(//button[@type='button'])[8]");
System.out.println(buyButtonText);
assertNotEquals("Loading...", selenium.getEval("storedVars['buyButtonText']"));
String bidPrice = selenium.getText("id=pretty_bid_price");
System.out.println(bidPrice);
assertNotEquals("Loading...", selenium.getEval("storedVars['bidPrice']"));
String askPrice = selenium.getText("id=pretty_ask_price");
System.out.println(askPrice);
assertNotEquals("Loading...", selenium.getEval("storedVars['askPrice']"));
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}代码在第一个assertNotEquals处失败。如有任何建议,我们将不胜感激。
发布于 2013-09-18 20:01:36
我不太熟悉Java和Selenium,但在我看来,您似乎是在尝试访问存储在字符串中的storedVars数组中的内容:
String sellButtonText = selenium.getText("xpath=(//button[@type='button'])[7]");然后后来
assertNotEquals("Loading...", selenium.getEval("storedVars['sellButtonText']"));如果你想使用storedVars数组,你不应该使用像selenium.store这样的东西吗?
发布于 2014-05-20 18:15:28
在我的java自动化框架中,我使用了WebDriver$Timeouts.class接口- implicitlyWait(long time,TimeUnit unit)方法。在这种情况下,恰好在初始化对象Webdriver的实例之后,粘贴以下代码:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);此方法指定如果没有立即出现元素,则在搜索元素时驱动程序应等待的时间。
希望这能有所帮助。
发布于 2020-03-05 17:52:05
尝试动态地等待页面上的内容加载。
selenium.wait("id=login_username")然后也尝试一下其中一个答案中提到的。
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);您可以通过增加秒数来发挥作用。这取决于加载页面所需的sla。即一些页面可能需要超过30秒的时间才能加载。
https://stackoverflow.com/questions/18858872
复制相似问题