私はツールSelenium
を使用して自動化を学習しようとする初心者です。私はこのウェブサイトを自動化しようとしています - http://newtours.demoaut.com/Selenium webdriverでradio radio bottonを見つけることができません
私はログインし、このラジオボタン(片道、ラウンドウェイ)でフライトファインダーにアクセスしようとしています。 しかし、私はエラーUnable to locate the element
を得ています。
次のように試してみてください。
- から取得した要素を見つけようとしました。
firebug
から取得しました。//*[@type='radio']//*[@value='oneway'] //*[contains(@type,'radio')] //*[contains(text(),'oneway'] //input[@type='radio' AND @value='oneway']
ラジオボタンを配置する
html
コードから構成される次のXPathを使用しも素子を配置する
CSS selector
を試みました。firebug
から得られたdriver.findElement(By.cssSelector("input[type=radio][value=oneway]"))
は
HTML
スクリプトを
implicit wait
を使用して待ち時間を追加しようとした
thread.sleep
です - 下記の
input type="radio" checked="" value="roundtrip" name="tripType"
Round Trip
input type="radio" value="oneway" name="tripType"
One Way
は私のコードです -
package gurutrial2;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class gurutrial2
{
public static WebDriver driver;
@BeforeTest
public final void preTest() {
System.setProperty("webdriver.firefox.marionette", "C:/Users/serajendran/Downloads/geckodriver-0.10.0 (1)");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.get("http://newtours.demoaut.com/");
driver.manage().window().maximize();
System.out.println(driver.getTitle());
Assert.assertEquals("Welcome: Mercury Tours", driver.getTitle());
}
@Test
public final void login() {
driver.findElement(By.name("userName")).sendKeys("invalidUN");
driver.findElement(By.name("password")).sendKeys("invalidPW");
driver.findElement(By.name("login")).click();
System.out.println("login in progress");
}
@Test
public final void flightFinder() {
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement oneWayRadioButton = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("oneway")));
oneWayRadioButton.click();
System.out.println("Clicked One Way");
}
}
ご協力いただければ幸いです。
このウェブサイトでは「あなたのため、承認が必要ですd。あなたの質問にターゲットラジオボタンの 'HTML'を追加してください。またiframe内にあるかどうかを確認し、iframeに 'HTML'を指定してください。 – Andersson
linktextにはいくつかのパディングや何かがあり、完全に一致していないかもしれません。 – Granitosaurus
入力してくれてありがとう: – Ashley