【windows7 selenium2+java 搭建】教程文章相关的互联网学习教程文章

java – Selenium WebDriver:当使用WebDriver.findElement定位时,等待元素存在【代码】

等待WebElement与WebDriverWait和ExpectedConditions一起出现是很方便的. 问题是,如果WebElement.findElment是唯一可能找到元素的方法,那该怎么办?因为它没有id,没有名字,没有唯一的类? WebDriverWait的构造函数只接受WebDriver作为参数,而不接受WebElement. 我已经设置了隐式等待时间,所以使用try {} catch(NoSuchElementException e){}似乎不是一个好主意,因为我不想等待这个元素的那么长时间. 这是场景: 有一个网页,其中包含...

java – 将选项传递给chrome驱动程序selenium【代码】

我试图禁用输出到控制台的chrome.如果我通过–start-maximized选项,它可以正常工作.我可能有错误的命令?DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.switches", Arrays.asList("--silent")); chrome = new ChromeDriver(_chromeservice,capabilities);我也试过了ChromeOptions options = new ChromeOptions();options.addArguments("silent");chrome = new ChromeDriv...

java – 如何使用Selenium单击href链接【代码】

我有一个html href链接<a href="/docs/configuration">App Configuration</a>使用Selenium我需要点击链接.目前,我使用下面的代码 – Driver.findElement(By.xpath("//a[text()='App Configuration']")).click(); 但它没有重定向到页面.我也试过下面的代码 – Driver.findElement(By.xpath(//a[@href ='/docs/configuration']")).click();但这是抛出异常 – org.openqa.selenium.ElementNotVisibleException: Element is not curren...

java – Selenium:submit()工作正常,但click()没有【代码】

我有提交按钮,它只是页面上的一个,而且它是在表单中. HTML部分:<form class="search-form ng-touched ng-dirty ng-valid" novalidate="" style="" xpath="1"><div class="row">...</div> <div class="row">...</div> <div class="row">...</div> <div class="form__actions" xpath="1"><div class="form__buttons"><!----><div class="btn__wrapper"><button class="btn btn__primary" type="submit">Select My Car</button></div...

java – org.openqa.selenium.WebDriverException:chrome无法访问 – 尝试启动新会话时【代码】

当我在Chrome上运行测试时,我经常会遇到无法访问Chrome的WebdriverException.它不会每次都发生.也许每15次一次.我不得不在Windows机器上运行所有东西,我有最新的Chrome,Chromedriver,Selenium-Webdriver版本. 我已经尝试设置环境变量“DBUS_SESSION_BUS_ADDRESS = / dev / null”.根本没有帮助. 任何人遇到这个并找到了解决方案?org.openqa.selenium.WebDriverException: chrome not reachable(Driver info: chromedriver=2.35.52...

java – Selenium webdriver 2.47.1如何等待页面重新加载【代码】

我正在使用webdriver(java)进行一项独特的测试,当你登录时页面重新加载,我一直无法等待元素加载,因为它在重新加载之前已经存在.到目前为止,我能够让它工作的唯一方法是使用thread.sleep,有没有办法监听页面刷新?解决方法:解决此问题的一种方法是,获取对所需元素的引用,该引用同时出现在登录页面和重新加载的页面上.然后,您可以使用ExpectedConditions.stalenessOf,然后您可以确定,该元素已从DOM中删除并创建了一个新元素.好吧,这个...

如何使用谷歌驱动程序解决“org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到localhost /”?

我在1周后面临上述问题.早些时候,它运作顺利.即使现在有时它工作正常,但大多数时候我得到“无法连接到localhost /”错误.

使用Java在Selenium WebDriver中使用PageObjects,Page Factory和WebDriverWait【代码】

我一直在使用Selenium WebDriver为我曾经使用过的一些项目实现功能测试.我正在尝试使用Page Factory设计模式与Page Factory来分解我的定位器.我还创建了一个静态WaitTool对象(singleton),它使用可选的超时参数实现了几种等待技术. 我目前的问题是我想在PageFactory尝试初始化WebElements之前使用我的wait方法.我想等待的原因是因为PageFactory可能会尝试在页面元素可用之前初始化页面元素. 这是一个示例PageObject:public class S...

java – 如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件?【代码】

我无法在Selenium Webdriver 3中为Firefox设置默认配置文件,因为FirefoxDriver类中没有这样的构造函数.import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.ProfilesIni; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test;public class SeleniumStartTest {@Testp...

Java Selenium Chromedriver.exe不存在IllegalStateException【代码】

这是我收到的错误消息:Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\Scott\workspace\Twitch%20Bot%20v2\bin\chromedriver.exeat com.google.common.base.Preconditions.checkState(Preconditions.java:197)at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:122)at org.openqa.selenium.remote.service.DriverService....

java – 无法在Selenium Webdriver中设置cookie【代码】

我正在尝试在使用webdriver打开它之前添加cookie到链接,但它一直给我这个错误:org.openqa.selenium.UnableToSetCookieException: Unable to set cookie (WARNING: The server did not provide any stacktrace information)请在下面找到我的代码:System.setProperty("webdriver.edge.driver","C:\\Program Files\\Latest Webdriver\\MicrosoftWebDrive.exe" ); EdgeDriver = new EdgeDriver(); Thread.sleep(2000); Cookie cookie...

java – 让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.printStackTr...

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

我在chrome中运行我的测试并在FF中获得了一个无法聚焦元素错误它工作正常.我已尝试过发布的决议但无济于事.我不知道该怎么做.希望有人可以提供帮助.提前致谢.driver.findElement(By.linkText("Add")).click(); List <WebElement> 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(); Javascrip...

java – 通过TestNG的Selenium的ChromeDriver和WebDriver导致4个错误【代码】

我正在做网站所说的,但它导致了4个错误……解决方法:正好有4个错误如下: >错误:ChromeDriver无法解析为某种类型 >解决方案:您需要添加以下导入import org.openqa.selenium.chrome.ChromeDriver; >在这里你可以找到关于chrome Webdriver can’t be resolved to a type error eclipse and java的讨论 >错误:无法将测试解析为某种类型 >解决方案:您需要添加以下导入import org.testng.annotations.Test; //or import org.junit.T...

软件测试神一样的超级好用的selenium 原创java util【代码】

以下是自己封装的seleniumJava工具类 可以自行拷贝用到项目中1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501...