Tag: selenium

如何保存在没有url的浏览器窗口中弹出的.pdf文件?

我正在使用我公司网站上提供的.pdf文件。 我不知道有任何方法可以下载它们并存储在一个文件夹中。 我单击以获取.pdf文件的链接具有以下源代码: 当我点击链接时,会在新的浏览器窗口中弹出一个.pdf文件,没有url和源代码。 我认为没有办法直接操作.pdf ,然后如何保存它以便从文件夹中操作.pdfs ? 谢谢

selenium元素位置

有没有一种简单的方法可以从另一个元素中找到一个子元素(这两个项目都是使用PageFactory定位的)? 我们有一套容纳许多模块的容器,我想确保它们显示在适当的位置。 API似乎只有以下方法: webElement.findElement(s).(By by); 有一种简单的方法可以执行以下操作: webElement.findElement(s)(WebElement webElement); 甚至更好: webElement.contains(WebElement webElement);

Java Selenium Chrome驱动程序 – 禁用图像加载

我试图运行chrome驱动程序而不加载任何图像,原因很明显。 我在网上发现了一段代码,但我认为它已经过时了 HashMap images = new HashMap(); images.put(“images”, 2); HashMap prefs = new HashMap(); prefs.put(“profile.default_content_settings”, images); ChromeOptions options =new ChromeOptions(); options.setExperimentalOption(“prefs”, prefs); DesiredCapabilities chromeCaps = DesiredCapabilities.chrome(); chromeCaps.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(chromeCaps); 根本不起作用.. 任何帮助都会受到极大的关注

selenium表格提交

我正在尝试使用selenium自动化表单提交。 但是,点击登录时运行的JavaScript会导致exception调用提交。 Selenium将提交指向localhost,而不是表单操作。 任何人都可以解释为什么会发生这种情况并善意地提供解决方案来解决这个问题。 这是表格: Sign On Sign On Please sign on and we’ll send you right along. Username Password Cancel Sign On Example function postOk() { document.forms[0][‘pf.ok’].value = ‘clicked’; document.forms[0].submit(); } function postCancel() { document.forms[0][‘pf.cancel’].value = ‘clicked’; document.forms[0].submit(); } function postOnReturn(e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = […]

当我显示一个对话框时,抛出exception“UnhandledAlertException:Modal dialog present”

我使用Internet Explorer 9使用Selenium Webdriver 2.42.2登录网站。 当我输入凭据并按下登录按钮时,会弹出一个modal dialog,说: 您已登录到同一物理设备。 您是否希望从之前的登录和登录再次注销? 所以有2个选项是/否。 我已经使用了driver.switchTo().alert.accept()但是警报在出现后很快就会消失,只需几分之一秒。 它没有按下Yes按钮。 我的代码: public class launch{ public static void main(Sting args[]){ driver.findElement(By.id(“login”)).click();// click performed launch obj = new launch(); if(obj.isAlertPresent(driver) == true) { Thread.sleep(3000); driver.switchTo().alert(); String a = driver.getTitle(); System.out.println(a); } } public boolean isAlertPresent(WebDriver drive) throws InterruptedException { try { Thread.sleep(2000); drive.switchTo().alert(); Thread.sleep(2000); return […]

使用Maven Postman插件运行测试后无法发送电子邮件

我一直在尝试整个早上,但是在使用Maven从命令行运行我的Selenium测试套件后,没有成功发送电子邮件。 以下是我们如何从命令行运行该套件。 mvn surefire:test 这是使用Surefire插件运行一套TestNG / Selenium测试。 这很好用,我们想继续使用它。 我需要的是一种在每次运行套件后通过电子邮件发送结果的方法。 我遇到了Postman插件,它看起来很完美。 唯一的问题是我根本无法让它工作。 这是我的maven .pom文件。 4.0.0 com.mysite.carelogic.selenium automation 0.0.1-SNAPSHOT carelogic-automation automation tests for carelogic webapp org.seleniumhq.selenium selenium-java 2.37.1 org.testng testng 6.8.7 log4j log4j 1.2.17 commons-lang commons-lang 20030203.000129 org.apache.poi poi-ooxml 3.8-beta4 org.apache.maven.plugins maven-surefire-plugin 2.16 testng.xml ch.fortysix maven-postman-plugin 0.1.6 send surefire notification deploy send-mail false false conner@mysite.com Automation Test […]

Selenium无法点击

selenium.click([xpath to object]) selenium点击方法似乎搞砸了。 它识别我想要点击的按钮并认为它点击它。 但屏幕上没有任何反应。 下一行涉及单击下一个屏幕上的另一个按钮。 它失败了,因为它无法找到按钮,因为第一次点击实际上并没有发生。 [编辑]看起来它只是在屏幕更改后无法点击。 它将点击登录按钮,然后加载新屏幕。 下一次点击失败,但是如果我轻轻推送(IE点击它的按钮),脚本中的所有跟随点击运行正常。 因此,屏幕更改后点击似乎有问题吗?

范围报告report.endTest(测试)方法?

我正在搞乱Selenium Java Extent Reports。 他们的新版本截止到10月12日,但我没有看到endTest方法。 他们尚未发布v3.0.0的完整文档。 大多数事情都是大致相同的用法,但endTest方法似乎不再可用。 有谁知道如何结束测试运行,以便可以在同一报告文件中显示多个测试? report = ExtentFactory.getInstance(date, time); test = report.createTest(“mytest”); test.log(Status.INFO, “test started”); // do some other stuff report.endTest(test); <– this is no longer an option. 任何人都知道结束测试的新方法是什么? 我能找到的只是 report.close(); 但这似乎并没有让我把多个测试放在同一个报告中。

geb.driver.DriverCreationException:无法从回调创建驱动程序

我正在设置一些Geb测试,我得到“geb.driver.DriverCreationException:无法从回调创建驱动程序”错误。 Geb将尝试启动测试浏览器窗口,但一旦它启动,我的测试都没有运行,我得到上述错误。 我刚刚对Firefox 32.0.2进行了自动Firefox更新,所以我怀疑新版本和Selenium Web Driver不再玩得很好了吗? 我该如何解决这个问题? 这是我一直在使用的Geb.config文件? 我没有改变它约5个月,它一直工作到现在… import org.openqa.selenium.firefox.FirefoxDriver import geb.waiting.WaitingSupport reportsDir = “target/geb-reports” driver = { //path is specific to each machine. This is the path to firefox.exe def pathToBin = ‘C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe’ System.setProperty(“webdriver.firefox.bin”,pathToBin) def driverInstance = new FirefoxDriver(); driverInstance.manage().window().maximize() driverInstance }

如何在Jenkins中运行Cucumber JVM测试

我有一个与Maven和Cucumber集成的Selenium Automation Framework。 我想用jenkins进行黄瓜测试。 我正在按照步骤运行它: 创建新作业>选择Maven项目 提供POM.xml的路径 添加Post Build Action Cucumber-JVM报告 保存 立即建造 执行这些步骤后黄瓜测试没有运行,但Build是成功的。