我写下面的代码来选择单选按钮,它工作正常,但今天它不工作 . 请找到代码和相应的错误消息
代码1:
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement radio = wait.until (ExpectedConditions.presenceOfElementLocated(By.id("0_2485A_StartDate")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", radio);
Error1:'线程中的异常“main”org.openqa.selenium.TimeoutException:在等待位于以下位置的元素存在10秒后超时:By.id:0_2485A_StartDate'
代码2:
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement radio = wait.until (ExpectedConditions.presenceOfElementLocated(By.id("Radio_0_2485A")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", radio);
错误2:'线程中的异常“main”org.openqa.selenium.TimeoutException:等待位于10秒后超时的元素:By.id:Radio_0_2485A'
CODE3:
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement radio = wait.until(ExpectedConditions.elementToBeClickable(By.id("0_2485A_StartDate")));
radio.click();
Error3:'线程中的异常“main”org.openqa.selenium.TimeoutException:等待元素可点击10秒后超时:By.id:0_2485A_StartDate'
码4:
WebDriverWait wait = new WebDriverWait(driver,10); WebElement radio = wait.until(ExpectedConditions.elementToBeClickable(By.id(“Radio_0_2485A”))); radio.click();
Error4:'线程中的异常“main”org.openqa.selenium.TimeoutException:等待元素可点击10秒后超时:By.id:Radio_0_2485A'
HTML:
<th class="radio">
<input id="0_2485A_StartDate" type="hidden" value="18/12/2015 00:01:00">
<input name="Products[0].ProductCode" title="5 Year Fixed Rate Until 28/02/2021 with £999 Fee" id="Radio_0_2485A" type="radio" value="2485A">
<label for="Radio_0_2485A">
5 Year Fixed Rate Until 28/02/2021 with £999 Fee
</label>
</th>
请建议 .
2 回答
presenceOfElementLocated
只是检查DOM
中存在的元素,因此,如果您使用ExpectedConditions
,您的代码将正常工作 .但是当我'm seeing, exception stacktrace states you'使用
elementToBeClickable
时,实际上elementToBeClickable
用于等待元素可见和可点击,而找到的元素被隐藏并且它永远不可见 .你找到了隐藏的元素,这就是你遇到麻烦的原因 .
你应该尝试找到如下的实际无线电元素: -
我无法复制您的实际Web浏览器方案,但只是尝试复制您的HTML代码并放入一个简单的html模板 . 我看到你几乎尝试了所有东西......如果可能的话,你可以把网址给别人看看页面 .
我试过这样的:
它起作用了 . 如果这有帮助,请告诉我 .