Tag: selenium web驱动程序

使用Selenium Web Driver检索HTMLinput的值

在一个web应用程序的HTML中有以下代码 <input type="text" name="prettyTime" id="prettyTime" class="ui-state-disabled prettyTime" readonly="readonly"> 实际显示在页面上的是显示时间的string。 在Selenium Web Driver中,我有一个引用<input>使用的WebElement对象 WebElement timeStamp = waitForElement(By.id("prettyTime")); 我想获得WebElement的价值,换句话说,就是打印在页面上的内容。 我尝试了所有的WebElement getter,并没有任何检索用户看到的实际值。 任何帮助? 谢谢。

Selenium WebDriver – testing元素是否存在

有没有办法如何testing一个元素是否存在? 任何findElement方法都将以一个exception结束,但这不是我想要的,因为它可能是一个元素不存在,那没关系,这不是testing的失败,所以一个exception不可能是解决scheme。 我发现这个职位: Selenium c#Webdriver:等待元素存在但是,这是为C#,我不是很擅长。 任何人都可以将代码翻译成Java? 我很抱歉,我在Eclipse中尝试过,但是我没有把它写入Java代码。 这是代码: public static class WebDriverExtensions{ public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds){ if (timeoutInSeconds > 0){ var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv.FindElement(by)); } return driver.FindElement(by); } }