以下の1 + 7の加算演算をテストしようとしました。しかし、わからない 属性 "name"が "Input"であるテキストフィールドの結果出力を取得する方法。Java selenium webdriver - テキストフィールドからテキストを取り出す
すべてのポインタが評価されます。
package hw9;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class calculator {
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.math.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testCalculator() throws Exception {
driver.get(baseUrl + "/students/calculators/source/basic.htm");
driver.findElement(By.name("one")).click();
driver.findElement(By.name("plus")).click();
driver.findElement(By.name("seven")).click();
driver.findElement(By.name("DoIt")).click();
String output = driver.findElement(By.name("Input")).getText();
System.out.println("Output: " + output); // **<--- Empty output**
assertEquals(8,output);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
問題のコードのHTMLを以下にリストされています
<td>
<div align="center"> <font size="+1">
<input name="Input" type="text" size="16">
</font></div>
</td>
By.id( "Input")を使って試してください。 –
要素にはIDがありません。名前と型の属性のみを持っています。 – user1972031
あなたは、最初の文章でidが "Input"である 'テキストフィールドと言っています。また、テストしているページのHTMLを投稿した場合にも役立ちます。 –