Tag: webdriver

如何使用selenium web driver for java获取特定optgroup下的选项?

例如,我想从多选选项列表字段中选择特定optgroup下的选项 pick1 pick2 pick3 pick4 如果选项列表字段如上所述,我可以使用 new Select(driver.findElement(By.id(“xyz”))).selectByVisibleText(“pick1”); new Select(driver.findElement(By.id(“xyz”))).selectByVisibleText(“pick2”); 从上面选择optgroup -Group1下的所有选项。 在这里,我知道Group1中存在哪些选项,因此我可以选择如上所述。 但我的要求是动态的,我需要选择optgroup-Group1下的所有选项。 如果我想动态选择包括组1和组2的所有选项 然后我可以使用 new Select(driver.findElement(By.id(“xyz”))).getOptions(); 将所有选项作为List获取,我可以将其存储为数组,然后我可以使用数组逐个选择所有选项 但是,如何才能在一个特定的optgroup下获得所有选项,比如Group1或Group2?

使用java测量网页的总加载时间

我正在创建一个应用程序来检查页面加载所需的时间。 到目前为止,我有这样的事情: long startTime = System.currentTimeMillis(); //load page and wait for it to finish long elapsedTime = System.currentTimeMillis() – startTime; 现在,我不只是想测量html文档加载的时间,而是整个dom。 基本上,如果它在浏览器中,我希望它能够测量加载微调器停止所需的时间。 我该怎么做才能做到最好? 我正在尝试WebDriver,但它似乎并不一致; 有时它会在仍然加载东西时考虑完成页面(我也尝试过隐式等待)。

如何使用Java在Selenium2(Webdriver)中键入Gmail正文文本

我尝试自动从Gmail发送电子邮件(https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1&ltmpl=default&ltmplcache=2)使用Selenium WebDriver和Java。 首先,我尝试使用Selenium IDE记录测试。 IDE无法记录电子邮件正文。 我尝试通过以下方式键入正文,但不幸的是它失败了。 driver.findElement(By.xpath(“// textarea [@ name =’body’]”))。sendKeys(“body text”); 错误是:FAILED:testSendingEmail org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时交互:30.02秒 有人可以帮帮我吗?

Selenium GhostDriver / PhantomJS:使用sendKeys()/ Javascript无法上传文件

我正在使用PhantomJSDriver / GhostDriver运行无头脚本,并尝试在编写电子邮件时上传gmail上的文件。 工具:Selenium与PhantomJS / GhostDriver。 html代码如下: Click the “Browse” button to select a file. Click “Done” when you’re finished. 1. 2. 3. 4. 到目前为止,我已经尝试了以下两种方法来上传文件,但它们都没有工作: 使用Javascript: wait.until(ExpectedConditions.presenceOfElementLocated(By.name(“file1”))); WebElement btnChoseFile = driver.findElement(By.name(“file1”)); System.out.println(btnChoseFile.isEnabled()); File file = new File(“attachments/Alan Morales.doc”); String script = “document.getElementsByName(\”file1\”)[0].value='” + file.getAbsolutePath() + “‘;”; jsexec.executeScript(script); System.out.println(“File attached…..”); 收到的例外情况: Exception in thread “main” org.openqa.selenium.ElementNotVisibleException: […]

Selenium:测试其Web属性“OVERFLOW”是自动/滚动的Web元素

在下一页中,只显示三个元素,我必须使用滚动条查看其他元素。 我正在使用selenium webdriver。 当我试图点击“第四行”或“第五行”时抛出了ElementNotVisibleException。 是否有任何方法可以移动scoll bar(或其他方式?)使“第四行”和“第五行”可见,然后可点击? Source code of this element: First Row Second Row Third Row Fourth Row Fifth Row

如何在testNG报告中包含故障屏幕截图

目前我以这种方式截取我的测试失败的截图: @AfterMethod(alwaysRun=true) public void catchExceptions(ITestResult result){ Calendar calendar = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat(“dd_MM_yyyy_hh_mm_ss”); String methodName = result.getName(); if(!result.isSuccess()){ File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(scrFile, new File((String) PathConverter.convert(“failure_screenshots/”+methodName+”_”+formater.format(calendar.getTime())+”.png”))); } catch (IOException e1) { e1.printStackTrace(); } } } 我可以将自己的屏幕截图添加到TestNG报告链接或图片中吗? 如果有,怎么样? 我在网上找到的只是FEST框架。 但由于我已经截取屏幕截图,我不想使用另一个框架。

如何用Chrome Webdriver关闭下载横幅?

在我的测试中,我下载了一个文件,它工作正常,但后来当我试图点击一个元素我无法滚动到视图时,页面底部的chrome下载对话框就挡了。 没有办法移动我需要点击进入视图的按钮,那么有没有办法用chrome webdriver关闭该下载框?

WebDriver PhantomJS无法找到元素,但可以在Firefox中正常工作

我已经把头撞到了墙上很长一段时间所以我想我会问“专家”为什么下面的代码不能用PhantomJS工作(输入密码),但用Firefox工作得很好。 最令人不安的是,一个字段条目(用户名)成功,但第二个条目根本不起作用。 页面加载很好,我已经包含测试代码,以validation其他组件加载得很好。 见下面的代码: import java.io.File; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.phantomjs.PhantomJSDriver; public class login { public static void main(String[] args) { WebDriver driver; Boolean verbose = false; //Change to true to test it with firefox String phantomPath = “../phantomjs-1.9.8-linux-i686/bin/phantomjs”; String url = “https://www.britishairways.com/travel/redeem/execclub/_gf/en_us”; if (verbose) { driver = new FirefoxDriver(); } else{ File file […]

如何从Selenium WebDriver,Java中的标签中获取价值

我有HTML代码: Samsung Galaxy SII (I9100) … … 我希望使用Selenium 2(WebDriver)从/ h3>标签获得三星Galaxy SII(I9100)的价值 谁知道怎么做?

如何使用Selenium和Java获取完整网页的屏幕截图?

如何使用Selenium WebDriver制作完整整个网页的截图? 我的Selenium WebDriver java代码如下: System.setProperty(“webdriver.chrome.driver”,”/home/alex/Downloads/chromedriver_linux64/chromedriver”); WebDriver driver = new ChromeDriver(); driver.get(“http://google.com”); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(RESULT_FILENAME)); 有任何想法吗?