1

このスクリプトは Selenium IDE から生成しました。Eclipse ではなく IDE で動作しています。Firefox 20 のみを実行し、Google にアクセスします。しかし、それは何も検索しません。

更新: setSpeed を Thread.Sleep(3000L) に置き換えましたが、エラー コメント「ロケーター戦略」に対処する方法がわかりません

package Selenium;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Selenium {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://www.google.fr/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testSelenium() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.id("gbqfq")).clear();
    driver.findElement(By.id("gbqfq")).sendKeys("selenium");
    // ERROR: Caught exception [ERROR: Unsupported command [setSpeed | 3000 | ]]
    // ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
    driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();
    // Warning: assertTextPresent may require manual changes
    assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*What is Selenium[\\s\\S][\\s\\S]*$"));
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

IDE ソースは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://www.google.fr/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=gbqfq</td>
    <td>selenium</td>
</tr>
<tr>
    <td>setSpeed</td>
    <td>3000</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>btnG</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Selenium - Web Browser Automation</td>
    <td></td>
</tr>
<tr>
    <td>assertTextPresent</td>
    <td>What is Selenium?</td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>
4

2 に答える 2

1

これは、古いセレン jar を使用していることが原因である可能性があります

から最新のスタンドアロン jar をダウンロードします。http://code.google.com/p/selenium/downloads/list

新しいライブラリを試して、それが機能するかどうかを確認してください。

于 2013-05-06T15:32:40.717 に答える