Tag: selenium webdriver

使用Selenium WebDriver未检测到Firefox警报框

错误net.serenitybdd.core.Serenity – 不存在警报(警告:服务器未提供任何堆栈跟踪信息) 当我尝试使用此代码检测警报时出现此错误: Alert alertBox = getDriver().switchTo().alert(); 警报弹出窗口确实显示,但是当我通过Selenium WebDriver和manualy执行操作时,它不完全相同。 这可能是问题的根源,但我不知道为什么弹出窗口不同。 手动完成时的警报 使用Selenium完成警报 这是调用警报的函数: function confirm_remove() { return window.confirm(“Alert message”); } 谢谢你的帮助 更新: 好的,我找到了一种绕过问题但没有真正解决问题的方法。 我尝试插入等待和睡眠,就像你建议我一样,但它没有解决问题,警报仍未被发现。 在我的项目中,我使用的是一个Test类,它调用我的Steps类中的步骤,该类从我的Page类调用webElements。 事情是,在单击“删除”按钮的步骤和管理警报的步骤之间,Selenium会丢失警报的处理。 所以我重新组合了这两个步骤,Selenium似乎很好地处理了警报。

WebDriverWait +搜索项目

创建激活码后,需要1-60秒才能将代码上传到系统中。 所以在创建新代码之后,我想使用WebDriverWait 60秒来确保在这个时间段内每3秒我想点击搜索按钮。 有没有办法做到这一点? (new WebDriverWait(driver, 60)) .until(ExpectedConditions.textToBePresentInElement(By.xpath(“//*[@id=’searchResults’]”), activationCode));

Selenium:如何解决org.openqa.selenium.InvalidElementStateException:无效的元素状态

我已经阅读了一些在线文章,他们都指向了1个方向,即页面加载时找不到元素。 在我的setData()中你可以看到我尝试了一些东西,比如使用wait,implicitwait和1st click,然后发送用户名。 然而,似乎没有任何工作。 我还想过在pageProperties中使用“wait”但后来改变了主意,因为这可能是一个糟糕的设计。 错误: Exception in thread “main” org.openqa.selenium.InvalidElementStateException: invalid element state 系统信息:Windows 10,ChromeDriver 2.37.544315,chrome = 65.0.3 代码 : public class Tour { public static WebDriver driver; //browser URL information public WebDriver getBrowser(String browser, String url){ System.setProperty(“webdriver.chrome.driver”, “C:\\Users\\Downloads\\chromedriver.exe”); if(browser.equals(“cc”)){ driver= new ChromeDriver(); } driver.get(url); return driver; } // User name and continue button […]

无法在selenium-java中使用xpath错误找到元素

这是我试图执行的代码 public WebDriver createPart() { try { driver.findElement(By.id(“username”)).sendKeys(“502409373”); driver.findElement(By.id(“password”)).sendKeys(“Magic14Magic”); driver.findElement(By.id(“submitFrmShared”)).click(); driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS); Select dropCountry = new Select(driver.findElement(By.id(“txtNewLocation”))); dropCountry.selectByVisibleText(“India”); driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); driver.findElement(By.xpath(“//button[@class=’btn’]/label”)).click(); driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS); Thread.sleep(10000); driver.findElement(By.xpath(“//li[@class=’icon-button add’]/span”)).click(); driver.findElement(By.xpath(“//div[@id=’ENCActions’]/a/label”)).click(); driver.findElement(By.xpath(“//label[starts-with(text(),’Create Part…’)]”)).click(); driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS); String parentWindowHandler = driver.getWindowHandle(); // Store your parent window String subWindowHandler = null; Set handles = driver.getWindowHandles(); // […]

Chrome浏览器无法导航到appium中的任何网站

我刚刚在android模拟器中安装了chrome.apk文件,它似乎安装成功。 但是当我尝试执行以下脚本时,它在模拟器设备中打开了Chrome浏览器,但没有显示谷歌主页。 简单的驱动程序退出。 示例代码:它似乎是启动浏览器,但没有导航到谷歌主页 public static WebDriver driver; @BeforeSuite public static void initalizeBrowser() throws Exception { try { DesiredCapabilities desired = DesiredCapabilities.android(); desired.setCapability(MobileCapabilityType.DEVICE_NAME, “Android Emulator”); desired.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”); desired.setCapability(MobileCapabilityType.PLATFORM_VERSION, “4.2.2”); desired.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”); desired.setCapability(MobileCapabilityType.APP_PACKAGE, “com.android.chrome”); desired.setCapability(MobileCapabilityType.APP_ACTIVITY, “com.google.android.apps.chrome.Main”); driver = new RemoteWebDriver( new URL(“http://127.0.0.1:4723/wd/hub”), desired); driver.get(“http://www.google.com”); } catch (Exception ex) { ex.printStackTrace(); } } @Test public void testCase1() […]

如何将字符串转换为By类型

如何将String转换为By类型。 以下是我的方案:以下面的方式在对象文件中保持对象标识 username=By.id(“username”) password=By.id(“password”) 在应用程序中,我想检索像这样的值 Properties prop=new Properties(); prop.load(“above properties file path”) driver.findelement(prop.getProperty(“username”)) //在eclipse中,它抱怨说“WebDriver类型中的方法findElement(By)不适用于参数(String)” 那么有人可以帮助我吗? 我可以使用下面或其他一些格式,但我想要上面的解决方案 username=”//*[@id=’username’]” username=”username” driver.findElement(By.xpath(prop.getProperty(“username”)) driver.findElement(By.id(prop.getProperty(“username”))

对同一个IEdriver实例进行多次测试 – 内存问题

我在我的节点上运行了很多selenium测试,这是windows机器。 为了通过避免在每次测试后启动/关闭IEDriver实例来加速测试执行,我决定为每个测试重用相同的驱动程序实例。 使用firefox和chrome一切正常,但IE11存在严重问题。 大约30分钟后,IE冻结没有任何exception,执行停止,它完全失去与我的节点的连接。 我可以看到IE11进程(iexplore.exe)使用大量内存资源(1.5 GB或更多),我需要使用任务管理器将其关闭以将其关闭。 有没有人遇到过这种问题以及如何避免它(除了为每个测试创建新的驱动程序实例),是否可以在同一个IEdriver实例上运行多个测试? 我正在使用IEDriver 3.0.0,Internet Explorer 11.在Windows Server 2012和Windows 8.1机器上也是如此。

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.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 62.52 seconds Build info: version: ‘2.52.0’, revision: ‘4c2593cfc3689a7fcd7be52549167e5ccc93ad28’, time: ‘2016-02-11 11:22:43’ System info: host: ‘CORPMNA7158A’, ip: ‘10.26.195.163’, os.name: […]

getWindowHandles()在firefox 58中不起作用。焦点仍然在父选项卡上,并且不会转移到下一个选项卡

我开始学习如何使用Selenium和Java在浏览器中处理多个选项卡。 看起来我的代码不起作用。 import java.util.ArrayList; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class HandlingWindows { public static void main(String[] args) throws InterruptedException { WebDriver driver= new FirefoxDriver(); driver.get(“https://www.facebook.com/”); String parent= driver.getWindowHandle(); System.out.println(“Parent Window is”+parent); //Get Data Policy WebElement we= driver.findElement(By.linkText(“Data Policy”)); //Click Data Policy link we.click(); //Create an arrayList ArrayList s1= new ArrayList(driver.getWindowHandles()); for(String […]

使用Selenium 3.0启动Firefox 46.0.1时获取IllegalStateException

我有Selenium 3.0.1版和Firefox版46.0.1。 在selenium 3.0.1 changelog中提到: Geckodriver现在是自动化Firefox的默认机制。 这是Mozilla为该浏览器实现的驱动程序,并且是自动化Firefox 48及更高版本所必需的 虽然我收到错误: java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置; 有关更多信息,请参阅https://github.com/mozilla/geckodriver 。 最新版本可以从https://github.com/mozilla/geckodriver/releases下载 执行以下代码时: @Test public void test() { WebDriver driver = new FirefoxDriver(); driver.get(“http://www.google.com”); driver.quit(); } 为什么我会收到此错误但是我使用的是Firefox版本<48.0? 是否必须将Geckodriver与Selenium 3.0.1一起使用? 如果我进行以下更改,上面的代码工作正常: System.setProperty(“webdriver.gecko.driver”,”path to geckodriver”); WebDriver driver = new FirefoxDriver();