私はJUnitのとSeleniumを使用して、このウェブサイトをテストしようとしています: https://www.oanda.com/currency/converter/同じxpathの2つの異なる要素はありますか?
私はだけでなく、「通貨私が欲しい」「私が持っている通貨」から単位を選択しようとしました。それから、私はxpathsが同じであることを知りました。 「通貨」コードのみが正常に実行されます。 「私が欲しい通貨」は常に失敗します。
XPathはdriver.findElement(By.xpath("//span[text() = 'GBP']")).click();
では、誰かがこれを助けてもらえますか?ありがとう。
CODE1:
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");
}
}
CODE2:
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