Tag: selenium

Selenium WebDriver StaleElementReferenceException

运行我的测试时出现此错误:org.openqa.selenium.StaleElementReferenceException:元素不再附加到DOM 关于如何解决上述exception的任何想法? 这发生在我的网格中,它有一个动态的ref Xpath表达式

如何使用selenium将javascript文件加载到DOM中?

我正在使用Selenium WebDriver尝试将外部javascript文件插入到DOM中,而不是将整个内容输入到executeScript中。 看起来它正确地将节点放入DOM中,但它只是忽略了源,即所述源js文件上的函数不运行。 这是我的代码: import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class Example { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get(“http://google.com”); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript(“document.getElementsByTagName(‘head’)[0].innerHTML += ‘<script src=\"\” type=\”text/javascript\”>’;”); } } 我链接的javascript文件的代码是 alert(“hi Nate”); 我已将js文件放在我的localhost上,我使用file:///调用它,然后在外部服务器上尝试了它。 没有骰子。 此外,在Java部分,我尝试使用该技巧附加’scr’+’ipt’,但它仍然无效。 当我使用Firefox的inspect元素检查DOM时,我可以看到它正确加载脚本节点,所以我很困惑。 我也尝试过这个解决方案,它显然是为另一个版本的Selenium(不是webdriver)制作的,因此无法在最低限度下工作: 在selenium中加载包含有用测试函数的外部js文件

如何在Selenium WebDriver中获取本机记录器

是否有可能以某种方式获取Selenium WebDriver使用的记录器? 我想捕获所有发出的命令的记录(例如:打开,等待,点击等)。 特别是我正在寻找一个java解决方案,因为我将测试导出到junit。 我在他们的网站上找到了这个代码,但它没有标准显示 DesiredCapabilities caps = DesiredCapabilities.firefox(); LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.DRIVER, Level.FINEST); caps.setCapability(CapabilityType.LOGGING_PREFS, logs); driver = new FirefoxDriver(caps);

Selenium等待加载Ajax内容 – 通用方法

是否有一种通用的方法让Selenium等到所有ajax内容都加载完毕? (不依赖于特定的网站 – 所以它适用于每个ajax网站)

WebDriver中不支持复合类名称错误

我有一种方法来计算divs的元素数量并返回它们的数量。 public int getNumberOfOpenBets() { openBetsSlip = driver.findElement(By.id(“form_open_bets”)); openBets = openBetsSlip.findElements(By.className(” cashout_noCash”)); return openBets.size(); } 这是页面源 WebDriver抛出以下错误:不支持复合类名称。 考虑搜索一个类名并过滤结果或使用CSS选择器。 org.openqa.selenium.InvalidSelectorException: Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors. For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: ‘2.31.0’, revision: ‘1bd294d185a80fa4206dfeab80ba773c04ac33c0’, time: ‘2013-02-27 […]

Chrome 59和Selenium / Fluentlenium的基本身份validation

Chrome 59已取消对https:// user:password@example.comurl的支持 。 我有一个使用此function的测试,现在已经坏了,所以我试图用等待认证弹出窗口的版本替换它并填写详细信息。 但以下内容在Chrome上不起作用(它没有将auth弹出窗口视为警报): alert().authenticateUsing(new UserAndPassword(“test”, “test”)); 仅限selenium的版本具有相同的问题: WebDriverWait wait = new WebDriverWait(getDriver(), 10); Alert alert = wait.until(ExpectedConditions.alertIsPresent()); alert.authenticateUsing(new UserAndPassword(“test”, “test”)); (基于此处给出的答案: 如何使用Java处理Selenium WebDriver的身份validation弹出窗口 ) 我可以看到在FireFox中处理此问题的几种解决方法,但Chrome没有。 有没有替代方法?

org.openqa.selenium.UnhandledAlertException:意外警报打开

我正在使用Chrome驱动程序并尝试测试网页。 通常它运行正常,但有一段时间我得到例外 – org.openqa.selenium.UnhandledAlertException: unexpected alert open (Session info: chrome=38.0.2125.111) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 16 milliseconds: null Build info: version: ‘2.42.2’, revision: ‘6a6995d’, time: ‘2014-06-03 17:42:30’ System info: host: ‘Casper-PC’, ip: ‘10.0.0.4’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: […]

隐含等待Vs有什么区别 在selenium webdriver中显式等待?

请分享有关selenium webdriver的知识。 请显示实时示例。

使用Selenium在Chrome中拍摄整页屏幕截图

我知道以前这是不可能的,但现在有了以下更新: https://developers.google.com/web/updates/2017/04/devtools-release-notes#screenshots 这似乎可以使用chrome dev工具。 现在可以在java中使用selenium吗?

Selenium许多日志(如何删除)

我用Firefox 48尝试了Selenium 3.0.1。 我已经尝试过以下代码: java.util.logging.Logger.getLogger( “com.gargoylesoftware.htmlunit”)setLevel(Level.OFF)。 java.util.logging.Logger.getLogger( “org.apache.commons.httpclient”)setLevel(Level.OFF)。 java.util.logging.Logger.getLogger(ProtocolHandshake.class.getName())setLevel(Level.OFF)。 但是一旦我在Netbeans下运行通常的测试,……日志仍然出现: Dec 02, 2016 9:17:53 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Attempting bi-dialect session, assuming Postel’s Law holds true on the remote end Dec 02, 2016 9:17:57 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS 解决这个问题的任何线索?