目前我正在尝试使用Selenium WebDriver捕捉屏幕截图。 但我只能获得整个页面的屏幕截图。 但是,我想要的只是捕获页面的一部分,或者也许只是基于ID或任何特定的元素定位器的特定元素。 (例如,我希望捕捉图片id =“蝴蝶”) 有没有办法通过选定的项目或元素捕捉屏幕截图?
我希望这只是我,但seleniumWebdriver似乎是一个完整的噩梦。 Chrome浏览器驱动程序目前无法使用,其他驱动程序是相当不可靠的,或者看起来如此。 我正在和许多问题作斗争,但是这里是一个。 随机地,我的testing将失败与一个 "org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_23'" 我正在使用webdriver版本2.0b3。 我已经看到FF和IE驱动程序发生这种情况。 我可以防止这种情况的唯一方法是在发生exception之前将实际的调用添加到Thread.sleep 。 虽然这是一个糟糕的解决方法,所以我希望有人可以指出我的错误,这将使这一切更好。
我有以下的HTML: <button name="btnG" class="gbqfb" aria-label="Google Search" id="gbqfb"><span class="gbqfi"></span></button> 我的下面的代码点击“Googlesearch”button在WebDriver中使用Java运行良好。 driver.findElement(By.id("gbqfb")).click(); 我想用WebDriver使用JavaScript来点击button。 我该怎么做?
我想点击一个单选button,出现在网页上。 代码如下: HTML代码: <div class="small-checkbox red-theme raleway-regular text-muted2 position-relative"> <div class="city-checkbox inline-block position-relative" ng-class="{'rounded-checkbox': main.current_city_id == 1, 'mb-20': main.ifDeviceIsPhone}"> <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect mh-20" for="mumbaiCity" ng-class="{'is-checked' : main.current_city_id == 1}"> <input type="radio" id="mumbaiCity" class="mdl-radio__button position-relative vertical-middle" name="city" value="1" ng-click="main.setCity('Mumbai', 1)"> <span class="mdl-radio__label position-relative font15"><img class="city-icon" src="../../../assets/img/cities/mumbai-icon.png">Mumbai</span> </label> </div> </div> Tesstcase: // demo-test.js describe('Protractor Demo App', […]
我在Selenium 2 Web Drivertesting中有以下代码,当我在debugging时工作,但大部分时间在构build中运行时失败。 我知道这是一定要做的事情,而不是刷新页面的方式,但不知道如何解决它,所以任何指针,我已经做错了赞赏。 我正在使用JSF primefaces作为我的Web应用程序框架。 当我点击添加新链接popup对话框出现一个input框,我可以input一个date,然后点击保存。 它是获取input元素input文本,我得到一个陈旧的元素参考例外。 提前致谢 import static org.junit.Assert.assertEquals; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; public class EnterActiveSubmissionIntegrationTest { Map<String, Map<String, String>> tableData = new HashMap<String, Map<String, String>>(); @Test public void testEnterActiveSubmission() throws Exception { […]
我的两个场景 – 1)首先 @driver.manage.timeouts.implicit_wait = 30 @wait = Selenium::WebDriver::Wait.new(:timeout => 45) # Time greater than implicit @wait.until {@driver.find_element(:tag_name => "body").text.include?("hey")} 这给驱动程序45秒来search文本(这是预期的) 2)其次 @driver.manage.timeouts.implicit_wait = 30 @wait = Selenium::WebDriver::Wait.new(:timeout => 5) # Time less than implicit @wait.until {@driver.find_element(:tag_name => "body").text.include?("hey")} 这现在给驱动程序30秒来search文本(不是预期的) 有没有办法使selenium只能等待explicit等待时间,而不是等待更长的时间? 注意 – 不声明隐含的等待时间不是一个选项,因为我不能让selenium挂起每次司机无法find的东西。 使用Selenium版本30,windows,ff
我正在寻找类似于waitForElementPresent东西来检查元素是否显示之前,我点击它。 我认为这可以通过implicitWait完成,所以我使用了以下内容: driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 然后点击 driver.findElement(By.id(prop.getProperty(vName))).click(); 不幸的是,有时它等待的元素,有时不。 我看了一会,发现这个解决scheme: for (int second = 0;; second++) { Thread.sleep(sleepTime); if (second >= 10) fail("timeout : " + vName); try { if (driver.findElement(By.id(prop.getProperty(vName))) .isDisplayed()) break; } catch (Exception e) { writeToExcel("data.xls", e.toString(), parameters.currentTestRow, 46); } } driver.findElement(By.id(prop.getProperty(vName))).click(); 它等待好了,但在超时之前,必须等待10秒钟5,50秒。 有点多。 所以我把隐含的等待时间设置为1秒,直到现在一切似乎都很好。 因为现在有些事情在超时之前等待10秒钟,但其他的事情在1秒之后超时。 你如何覆盖代码中存在/可见的等待元素? 任何提示是可观的。
我想在rediff.com中处理login部分,但下面的代码不适用于此: driver.get("http://www.rediff.com/"); WebElement sign = driver.findElement(By.xpath("//html/body/div[3]/div[3]/span[4]/span/a")); sign.click(); String myWindowHandle = driver.getWindowHandle(); driver.switchTo().window(myWindowHandle); WebElement email_id= driver.findElement(By.xpath("//*[@id='signin_info']/a[1]")); email_id.sendKeys("hi"); 如果myWindowHandle不是正确的string,那么让我知道如何得到popup窗口名称,因为我找不到popup窗口的名称。
我正在将selenium1代码转换为selenium2,无法find任何简单的方法来select下拉菜单中的标签或获取下拉选定的值。 你知道在Selenium 2中怎么做? 以下是在Selenium 1中工作的两个声明,但不是在2中: browser.select("//path_to_drop_down", "Value1"); browser.getSelectedValue("//path_to_drop_down");
根据以前的问题,我将Selenium更新到了2.0.1版。但是现在我又遇到了另一个错误,即使configuration文件存在于/tmp/webdriver-py-profilecopy : 文件“/home/sultan/Repository/Django/monitor/app/request.py”,第236行,执行 浏览器= Firefox(个人资料) 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py”,第46行,在__init__ self.binary,超时), 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py”,第46行,在__init__ self.binary.launch_browser(self.profile) 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py”,第44行,在launch_browser self._wait_until_connectable() 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py”,第87行,在_wait_until_connectable 引发WebDriverException(“无法加载configuration文件。configuration文件目录:%s”%self.profile.path) selenium.common.exceptions.WebDriverException:无法加载configuration文件。 configuration文件目录:/ tmp / webdriver-py-profilecopy 哪里不对? 我该如何解决这个问题?