Tag: selenium webdriver

使用Selenium Webdriver获取div中的项目列表

说我有以下内容 现在我想根据我提供的索引在复选框上打勾。 所以我写了一个像下面这样的方法 如何访问div class =“facetContainerDiv”中的所有元素? 我试过了 List elementsList = driver.findElements(By.cssSelector(“.facetContainerDiv”)); for(WebElement checkBox:elementsList) { int i=0; checkBox = elementsList.get(i); bla bla bla.. } 在上面的代码中,elementsList只有一个“type”元素为null。

ChromeDriver(functionfunction)已弃用

我将ChromeDriver 2.33与WebDriver 3.6.0一起使用,并尝试设置文件下载的默认目录。 Map prefs = new HashMap(); prefs.put(“download.default_directory”, Vars.DOWNLOAD_FOLDER_ROOT); DesiredCapabilities caps = DesiredCapabilities.chrome(); ChromeOptions options = new ChromeOptions(); options.addArguments(“–start-maximized”); options.setExperimentalOption(“prefs”, prefs); caps.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(caps); 我在docs中找到了这个: 请改用ChromeDriver(ChromeOptions)。 创建一个新的ChromeDriver实例。 这些function将传递给chromedriver服务。

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 […]

如何正确设置Java / Selenium配置以运行自动化测试?

我正在尝试设置selenium webdriver与Browserstack一起使用Java进行自动化测试。 我安装了Selenium for java,我从browserstack的网站https://www.browserstack.com/automate/java#configure-capabilities复制并粘贴了代码,以建立一个示例自动化测试。 我从我的终端运行了javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java (JavaSample.java是带有selenium配置代码并带有示例测试的文件),我收到以下错误: JavaSample.java:1: error: package org.openqa.selenium does not exist import org.openqa.selenium.By; ^ JavaSample.java:2: error: package org.openqa.selenium does not exist import org.openqa.selenium.Platform; ^ JavaSample.java:3: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebDriver; ^ JavaSample.java:4: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebElement; ^ JavaSample.java:5: error: package org.openqa.selenium.remote does […]

selenium chromedriver认证代理

我需要在java中的selenium 2中使用chromedriver webdriver连接到具有用户名和密码(即USERNAME:PASSWD @ IP:PORT)的代理服务器。 我已经找到了如何在不使用用户名和密码的情况下完成它,但是还没有找到办法。 谢谢。

selenium web驱动程序中的sendKeys()

我是Selenium的新手。 我只想将密钥发送到用户名文本框并一次发送一个tab键,以便文本框可以检查用户名的可用性。 这是代码: driver.findElement(By.xpath(“//label[text()=’User Name:’]/following::div/input”)).sendKeys(“UserName”); driver.findElement(By.xpath(“//label[text()=’User Name:’]/following::div/input”)).sendKeys(Keys.TAB); 但是这个没有用。 请帮帮我。

Selenium WebDriver无法按链接文本查找元素

我正在尝试选择包含锚点的元素,但文本被隐藏在div内部的段落中。 这是我正在使用的HTML: Smoke Sequential 我用来试图阻止它的代码是针对“Smoke Sequential”文本: driver.findElement(By.linkText(service)).click(); 变量’service’在其中包含“Smoke Sequential”。 当我运行它时,我收到以下错误: org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”link text”,”selector”:”Smoke Sequential”} 任何帮助将不胜感激。

使用Internet Explorer 11和Selenium(任何版本)和IEWebDriver(任何版本)都找不到任何元素

我已经搜遍了所有的答案,我找不到任何解决方案。 我试图在IE11中运行我的Selenium测试。 所有其他浏览器都可以正常工作(包括Edge)。 如下的简单测试将导致问题…… System.setProperty(“webdriver.ie.driver.loglevel”,”TRACE”); System.setProperty(“webdriver.ie.driver.logfile”, “C:/Projects/logme.txt”); driver = new InternetExplorerDriver(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.get(“http:www.google.com”); driver.findElement(By.id(“lst-ib”)).click; IE11将启动并导航到一个URL,但它无法在任何页面上的任何位置找到任何元素。 再一次,我知道人们有这个问题,但没有任何建议解决了我的问题。 这是我每次都回来的错误: org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 3.23 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: […]

在Firefox中自动下载pdf文件

我正在用Selenium和JUnit进行测试。 我正在尝试导出报告(pdf和xls)。 使用Selenium,我单击下载链接,并执行verifcar断言文件位于正确的文件夹中。 我能够使用xls测试,但Firefox总是询问我想用PDF做什么。 Firefox,Selenium的配置如下: String downloadPath = new File(“src/test/resources/firefox_download”).getAbsolutePath(); firefoxProfile.setPreference(“browser.download.dir”, downloadPath); firefoxProfile.setPreference(“browser.download.lastDir”, downloadPath); firefoxProfile.setPreference(“browser.download.manager.showWhenStarting”, false); firefoxProfile.setPreference(“plugin.disable_full_page_plugin_for_types”, “application/pdf,application/vnd.fdf”); firefoxProfile.setPreference(“browser.download.folderList”, 2); firefoxProfile.setPreference(“browser.download.defaultFolder”, downloadPath); firefoxProfile.setPreference(“browser.helperApps.neverAsk.saveToDisk”, “application/pdf, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff”); // tipo específico firefoxProfile.setPreference(“browser.helperApps.alwaysAsk.force”, false); 我可以手动更改,在这里: 或者在这里: 但我需要以编程方式执行此操作,否则测试将在其他地方失败(例如服务器/声纳) […]

WebDriver Java:将现有的webdriver浏览器会话重新连接到驱动程序实例

我正在寻找一种方法将现有的webdriver浏览器会话重新连接到驱动程序实例,以便我可以再次控制浏览器。 到目前为止,我已尝试过以下方法: I. ========================================== 参考: https : //stackoverflow.com/a/38827934/2285470 浏览器: Firefox v.51.01 / Chrome v.56.0.2924.87 司机: geckodriver v.1.14 / chromedriver v.2.27 解决方案: 1.创建扩展RemoteWebDriver的自定义类 public class RemoteDriver extends RemoteWebDriver { public RemoteDriver(URL url, String sessionId) { super(); setSessionId(sessionId); setCommandExecutor(new HttpCommandExecutor(url) { @Override public Response execute(Command command) throws IOException { if (command.getName() != “newSession”) { return super.execute(command); } […]