Tag: webdriver

如何在TestNg类之间传递WebDriver的单个实例

我无法在网上的任何地方找到一个不同的答案。 我有多个TestNg类来运行测试,BrowserFunctions,登录,搜索,过滤(测试亚马逊的实践)。 我还有一个BrowserLauncher类,它根据浏览器名称和testng.xml文件返回相应的webdriver。 BrowserFunctions.java public class BrowserFunctions { BrowserLauncher bl = new BrowserLauncher(); WebDriver driver; StringBuilder sb = new StringBuilder(); @BeforeSuite public void initialioseBrowser() { driver = bl.launchBrowser(“Firefox”); } @Parameters({ “URL” }) @BeforeSuite public void invokeURL(String URL) { driver.get(URL); } @AfterSuite public void closeBrowser() { driver.close(); } Login.java public class Login { BrowserLauncher bl = […]

创建类对象的类

我是新手,我正在学习webdriver和java :)我有初学者的问题。 我创建了类locators(findBy)和使用此定位器的方法( senKeys() , click()等) – 我使用pagefactory 。 HomePage LoginPage … 我的主类AddNewLeadTest是一个类,我用类定位器初始化方法,我这样做: HomePage hp = new HomePage(driver); hp.loginButton.click() 我想这样做: HomePage.loginButton.click() 它更快,我不必为每个xxxPage类在AddNewLeadTest创建新对象。 我应该如何编写类/方法来简化创建新对象? 我找到了我想在我的项目中使用的示例(在C#中),但我不知道如何在Java中使用它。 见下文。 public static class Pages { private static T GetPage() where T : new() { var page = new T(); PageFactory.InitElements(Browser.Driver, page); return page; } public static AboutPage About { get […]

断言网页中缺少元素,给出NoSuchElementException

需要声明网页中没有这样的元素,当尝试使用fieldValueBox.isDisplayed(); 而不是“假”它抛出“NoSuchElementFound”exception。 现在我正在使用’try catch’并在’catch’中做出决定

我无法在Selenium中重写Java的C#解决方案

我在C#上修改了FireFox浏览器时遇到了一些问题。 当浏览器打开并出现错误时: TypeError:给定browserName [object String]“firefox”,但我的名字是[object String]“anotherbrowser” 我认为,这是因为浏览器的名称为“anotherbrowser”而不是“firefox”的二进制代码。 所以我在Java上找到了解决方案: FirefoxOptions options = new FirefoxOptions(); options.setBinary(“Path to browser binary”); options.setCapability(“browserName”, “anotherbrowser”); options.setCapability(“marionette”, false); driver = new FirefoxDriver(options); 我测试了它,它的工作正常。 但我需要C#,所以我试着重写它: DesiredCapabilities cap = DesiredCapabilities.Firefox(); cap.SetCapability(“browserName”, “anotherbrowser”); cap.SetCapability(“firefox_binary”, @”Path to browser binary”); IWebDriver driver = new FirefoxDriver(cap); //here’s error 但是我收到了一个错误: browserNamefunction已经有一个选项。 请改用。 请帮我重写Java解决方案到C#。 我遇到了麻烦,因为在C#中没有相同的方法,比如在Java中: “options.setCapability(”“,”“);” Ps我不能使用原始的Firefox浏览器,因为它与我修改过的Firefox没有相同的优势。

无法使用selenium webdriver在Compose E-mail页面上的To(Email id)字段中发送密钥

“ To ”Buttom 无法从selenium webdriver 获取密钥 。 在输出中,它显示无法定位元素。 “To”在iframe中,我使用了I帧但是它也没用。 import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class mail { public static void main(String[] args) throws InterruptedException { System.setProperty(“webdriver.gecko.driver”, “D:\mozilla driver\geckodriver.exe”); WebDriver driver=new FirefoxDriver(); driver.get(“https://www.mail.com/int/”); driver.findElement(By.xpath(“.//*[@id=’login-button’]”)).click(); driver.findElement(By.xpath(“.//*[@id=’login-email’]”)).sendKeys(“rahulrahulxyz@mail.com”); driver.findElement(By.xpath(“.//*[@id=’login-password’]”)).sendKeys(“incredible”); driver.findElement(By.xpath(“.//*[@id=’login-form’]/button”)).click(); driver.switchTo().frame(“thirdPartyFrame_home”); driver.findElement(By.linkText(“Compose E-mail”)).click(); Thread.sleep(5000); driver.switchTo().frame(“thirdPartyFrame_mail”); // **here is error** driver.findElement(By.xpath(“.//*[@id=’idbd’]/div[2]/div[1]/div[1]/div[2]/div/div/ul/li/input”)).sendKeys(“abcde@mail.com”); } }

使用java运行ghostdriver会出错

我正在使用远程ubuntu机器来运行我的测试用例。 我有jenkins配置github。 我可以使用我的windows7机器使用putty.exe访问这台机器。 我想使用phantomjs运行无头测试用例(调度作业),即当我的Windows机器关闭时,测试将在远程ubuntu机器上运行,该机器始终打开。 现在的问题是,当我现在构建它会给出错误: Caused by org.openqa.selenium.HasInputDevices … … 我的setup()方法和pom看起来像: 建立() DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,”/usr/bin/phantomjs”); driver = new PhantomJSDriver(caps); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(Production); 的pom.xml com.github.detro.ghostdriver phantomjsdriver 1.0.3 编辑:已通过添加selenium 2.34.0 jar依赖项解决了HasInputDevices的问题 但是在运行上面测试时仍然会出错: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: […]

Selenium,点击元素,挂起

这是关于java中的selenium webdriver。 如果单击一个元素,通常会很快,但有时当服务器忙时,它会在浏览器顶部显示正在连接…并挂起。 通常要处理等待,代码是: driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); 但在这种情况下,当服务器挂起click()时,这不会在时间限制之后抛出exception,因为webdriver在点击完成连接到下一个url之前不会开始计数。 有没有人以前处理过这个问题,怎么做? 有没有办法完成click()和submit() ?

Selenium Java打开新窗口,关闭它,再次控制主窗口

我发现我的问题与我搜索过的所有内容都不同,因为我需要在代码中打开一个新窗口(而不是单击UI中的链接)。 所以我已经有一个驱动程序处理我唯一的窗口,然后我这样做: //save the handle of the current (only) window open right now String MainWindowHandle = driver.getWindowHandle(); //open a new firefox window driver = new FirefoxDriver(); //in the new window, go to the intended page driver.navigate().to(foo); //do some stuff in the pop up window.. //close the popup window now driver.close(); //switch back to the main […]

如何在桌面浏览器上使用webdriver移动网络

我使用selenium webdriver进行AUT(应用程序测试)的function测试自动化。 AUT是响应式网络,我几乎完成了桌面浏览器的不同测试用例。 现在相同的测试用例也适用于移动浏览器,因为可以从移动浏览器访问AUT。 因为当我们在移动浏览器中打开时它是响应式web,所以UI具有一些不同的表示。 所以我们也需要为移动浏览器运行这些测试。 对于使用safari浏览器的用户代理function的手动测试团队 Safari浏览器菜单 – >开发 – >用户代理 它满足了我们对手动测试的需求。 如果我们可以通过自动化做同样的事情,即在桌面浏览器上使用某些twik运行测试,那么它也被认为是移动Web自动化完成。 我的问题是如何使用web驱动程序来修改标题。 url是相同的,因为只有一个网络应用程序。 我的自动化测试使用FirefoxDriver和chromeDriver在firefox上正常运行。 两种浏览器都有类似的开发工具,但我无法通过自动化来利用它。 我们使用的是selenium2.53.0。 我们的IVY文件具有以下与selenium相关的依赖关系。 任何人都可以提供建议并帮助我如何运行我的测试来实现它以及我需要做的相关代码更改是什么? 谢谢。

Selenium web驱动程序和多语言

我用selenium webdriver + java。 例如,当我想通过xpath获取一些数据/文本时 driver.findElement(By.xpath(“.//table[3]/tbody/tr/td/table[1]/tr[1]/td[1]”)).getText() 如果我想要获得俄文文本,它会让我回头看看。 符号,而不是文本。 用英语它可以正常工作。 有任何想法吗? 谢谢!