我在java中编写了一个简单的selenium web驱动程序脚本来选择并点击一个单选按钮,但我无法选择并点击网页上的第二个单选按钮'ONE WAY FLIGHT':{{1} }
这是我的代码:
http://www.lot.com/pl/en
这就是错误:
WebDriver driver = new FirefoxDriver(); String web = "http://www.lot.com/pl/en"; driver.get(web); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); WebElement element; element = driver.findElement(By.id("select2-departureAirport-container")); element.click(); element.sendKeys("WAW"); element.sendKeys(Keys.ENTER); /* RADIO BUTTON ERROR */ element = driver.findElement(By.cssSelector("input[value='SINGLE']")); elementRadio.click();
这是网页Exception in thread "main" org.openqa.selenium.ElementNotInteractableException:
上的HTML片段:
http://www.lot.com/pl/en
我无法理解它为什么会抛出异常。
答案 0 :(得分:0)
使用以下代码: -
WebDriver driver = new FirefoxDriver();
String web = "http://www.lot.com/pl/en";
driver.get(web);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement element;
element = driver.findElement(By.id("select2-departureAirport-container"));
element.click();
element.sendKeys("WAW");
element.sendKeys(Keys.ENTER);
/* RADIO BUTTON ERROR */
element = driver.findElement(By.cssSelector("input[value='SINGLE']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
答案 1 :(得分:0)
您尝试使用xpath吗?
elementRadio = driver.findElement(By.xpath("//*[@id="flightBookingForm"]/div[2]/div[1]/div/fieldset/label[2]/span[2]"));
elementRadio.click();