Tag: selenium webdriver

使用selenium上传文件

如何使用selenium webdriver通过窗口提示从本地上传文件? 我想执行以下操作: 单击窗口上的“浏览”选项 从窗口提示符转到保存文件的本地位置 选择文件并单击“打开”以上载文件。

Selenium Webdriver:在文本字段中输入文本

当我在文本字段中输入文本时,它将被删除。 这是代码: String barcode=”0000000047166″; WebElement element_enter = _driver.findElement(By.xpath(“//*[@id=’div-barcode’]”)); element_enter.findElement(By.xpath(“//html/body/div[1]/div[3]/div[1]/form/div/div/input”)).sendKeys(“barcode”);

让Selenium暂停X秒

我想要完成的是浏览页面,等待加载某些内容然后获取并保存屏幕截图。 我已经拥有的代码是 WebDriver driver = new FirefoxDriver(); driver.get(“http://www.site.com”); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); try { File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(“/home/Desktop/image.png”)); } catch (Exception e) { e.printStackTrace(); } driver.close(); 我需要等待的原因,即使页面被加载是因为它将被加载,但在网站上我想要在几秒钟后拍摄加载图片的内容。 由于某种原因页面没有等待, 是否有另一种方法可以让驱动程序/页面等待X秒?

如何在多个浏览器中运行Selenium测试,以便使用Java进行跨浏览器测试?

我正在使用Selenium WebDriver和Java和TestNG框架。 我想在一个代码中一次使用Firefox,IE,Chrome进行跨浏览器测试。 我只能将Firefox初始化为 driver = new FirefoxDriver(); 但无法以相同的方式初始化其他浏览器。 例如: driver = new InternetExplorerDriver(); 给出错误InternetExplorerDriver cannot be resolved. driver = new ChromeDriver(); 给出错误ChromeDriver cannot be resolved. 如何初始化IE和Chrome并在所有需要的浏览器中执行我的测试?

获取无法使用java / selenium将元素集中在chrome和edge中

我在chrome中运行我的测试时遇到无法聚焦元素错误,并且FF中的边缘工作正常。 我已尝试过发布的决议但无济于事。 我不知道该怎么做。 希望有人可以提供帮助。 提前致谢。 driver.findElement(By.linkText(“Add”)).click(); List groups = new Select(driver.findElement(By.xpath(“/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[1]/select”))).getOptions(); groups.get(3).click(); JavascriptExecutor js = (JavascriptExecutor)driver; WebElement groupRole = driver.findElement(By.xpath(“/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[2]/label[2]”)); js.executeScript(“arguments[0].click();”, groupRole); driver.findElement(By.xpath(“/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[2]/div/div/div[2]/label[2]”)).sendKeys(” “); // Check to see if the user should be made active and set active checkbox to on if value in file is “active” if (activeFlag.equals(“active”)) { driver.findElement(By.xpath(“/html/body/div[1]/section/div/article/form/fieldset/div[3]/div[1]/div[1]/div/div/input”)).sendKeys(” “); } // If […]

Selenium可以使用JUnit截取测试失败的截图吗?

当我的测试用例失败时,特别是在我们的构建服务器上,我想拍一张屏幕的图片/截图来帮助我调试以后发生的事情。 我知道如何截取屏幕截图,但我希望在浏览器关闭之前,如果测试失败,JUnit中的方法可以调用我的takeScreenshot()方法。 不,我不想编辑我们的bazillions测试来添加try / catch。 我想也许,也许可能会被说成一个注释。 我的所有测试都有一个共同的父类,但我想不出我能做什么来解决这个问题。 想法?

等待直到文本字段中的文本存在

在webdriver中,如何要求webdriver等到文本字段中存在文本。 实际上我有一个kendo文本字段,其值来自数据库,需要一些时间来加载。 一旦它加载我可以继续进行。 请帮忙

如何使用JAVA在Selenium WebDriver中打开Chrome Developer控制台

我想询问如何在执行selenium测试期间打开Chrome开发者控制台。 目前,当测试正在执行时,我手动打开控制台点击F12,测试立即停止响应并在一段时间后失败。 任何人都可以告诉我如何在打开开发人员控制台的情况下启动我的测试,因此我可以捕获/观察测试执行期间发生的控制台错误。

如何在Selenium中使用已经打开的firefox进行测试

这个宣言 WebDriver driver = new FirefoxDriver(); 总是打开Firefox的新实例窗口。 它不使用已经打开的Firefox。 任何人都可以让我知道如何使用已经打开的Firefox进行测试而不是打开一个新的?

如何使用java运行Selenium的ghostdriver

我想使用phantomJS进行一些网络测试,我遇到了GhostDriver ( https://github.com/detro/ghostdriver )。 我使用自述文件中的说明构建它,我可以在指定的端口上运行它,但我不知道如何从我的Java代码访问Web驱动程序。 为了澄清,我在ruby中看到了这个例子: caps = { :browserName => “phantomjs”, :platform => “LINUX” } urlhub = “http://key:secret@hub.testingbot.com:4444/wd/hub” client = Selenium::WebDriver::Remote::Http::Default.new client.timeout = 120 @webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client @webdriver.navigate.to “http://www.google.com/” puts @webdriver.title @webdriver.save_screenshot(“./screenshot.png”) @webdriver.quit 我只是不确定如何从java做同样的事情。