0
我將嘗試使用JUnit和Selenium測試此網站: https://www.oanda.com/currency/converter/兩個不同的元素具有相同的xpath?
我試圖從「貨幣無我有」,以及「貨幣我想要的」選擇單位。然後我發現xpaths是一樣的。只有「貨幣我有」代碼可以成功運行。 「我想要的貨幣」總是失敗。
的XPath是driver.findElement(By.xpath("//span[text() = 'GBP']")).click();
可能有人在幫助呢?謝謝。
代碼1:
public class Currency_I_Have {
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception {
driver.manage().window().maximize();
driver.get("https://www.oanda.com/currency/converter/");
}
@Test
public void test() {
driver.findElement(By.id("quote_currency_input")).click();
driver.findElement(By.xpath("//span[text() = 'GBP']")).click();
WebElement Amount = driver.findElement(By.id("quote_amount_input"));
Amount.clear();
Amount.sendKeys("100");
}
}
代碼2:
public class Currency_I_Want {
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception {
driver.manage().window().maximize();
driver.get("https://www.oanda.com/currency/converter/");
}
@Test
public void test() {
driver.findElement(By.id("base_currency_input")).click();
driver.findElement(By.xpath("//span[text() = 'GBP']")).click();
WebElement Amount = driver.findElement(By.id("base_amount_input"));
Amount.clear();
Amount.sendKeys("200");
}
}
工作正常。非常感謝。 – robertredrain