Tag: selenium

隐式vs显式vs流利等待

隐式,明确,流利等待有什么区别? 如果我们在隐式等待和10秒之前设置10秒,则在3秒内只有元素到达。 那个时候会发生什么? 它将等待10秒或继续进行。

为什么Selenium驱动程序无法识别Facebook登录页面的ID元素?

我刚刚开始在线课程学习Selenium webdriver。 由于我是测试和Java编程的初学者,所以请帮助我。 我试图运行自动化代码以在Facebook登录页面中自动填充用户名。 初始运行程序已成功输出。 但在第二次尝试时,我遇到了以下错误 org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:”id”,”selector”:”email”} 之后,我用谷歌搜索并发现这个问题试图在我的代码中复制这个答案 。 public class Helloworld { public static void main(String[] args) { System.setProperty(“webdriver.chrome.driver”,”C:\\Seenu\\Selenium\\Driver” +”\\Chromedriver\\chromedriver.exe”); WebDriver drive = new ChromeDriver(); drive.get(“https://www.facebook.com”); // part copied from other SO question //Copied code starts here with little modification List elements = drive.findElements(By.id(“email”)); if(elements.size() > […]

Selenium测试脚本通过新的ajax登录表单登录谷歌帐户

我可以编写脚本来将我的电子邮件地址放入电子邮件元素中。 但是,一旦点击下一步脚本,谷歌就会使用ajax动态地将该电子邮件元素替换为密码元素。 这是我被困住的地方,无法在该元素中提供密码而且无法登录。 url: https : //accounts.google.com/signin/v2/identifier?flowName = GlifWebSignIn&flowEntry = ServiceLogin 请编写selenium测试脚本来实现此目的。

通过多个类名来查找div元素?

我想识别那个web元素。 它只定义了这两个类。 我无法执行以下操作,因为className不采用空格分隔值。 什么是替代品? @FindBy(className = “value test”) @CacheLookup private WebElement test;

使用java中的selenium webdriver登录Gmail

import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class NewGmail { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); String url = “https://accounts.google.com/signin”; driver.get(url); driver.findElement(By.id(“identifierId”)).sendKeys(“cp8805”); //driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); WebDriverWait wait=new WebDriverWait(driver, 20); driver.findElement(By.xpath(“//span[@class=’RveJvd snByac’]”)).click(); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS); driver.findElement(By.xpath(“//input[@class=’whsOnd zHQkBf’]”)).sendKeys(“xxxxxx”); driver.findElement(By.xpath(“//span[@class=’RveJvd snByac’]”)).click(); } } 在邮件ID之后,我的密码也会写入id框选项并且服务器重定向到下一个密码页面。 我想问一下我将做什么,以便我的密码只能输入密码页面。

如何为Testng和runnnig创建可执行jar文件应该是Xml文件

我目前正在Eclipse IDE上研究selenium web驱动程序和testng。 我通常从我创建的XML文件运行测试,该文件运行eclipse中的所有方法。 现在我想创建一个简单的可执行jar,它应该做同样的事情,即它的运行点应该是XML文件,以便执行每个测试。 我正在努力解决这个问题。 请给我一些如何进一步了解它的建议

为什么人们应该更喜欢在IE中使用CSS而不是XPath?

我正在开发一个只与IE7和IE8兼容的应用程序。 我不知道为什么,但有些人建议在识别IE中的元素时使用CSS而不是XPath。 当我访问官方Selenium网站时。 我看了这条消息 WebDriver尽可能使用浏览器的本机XPathfunction。 在那些没有本机XPath支持的浏览器上,我们提供了自己的实现。 除非您了解各种xpath引擎中的差异,否则这可能会导致一些意外行为。 我想知道在哪里可以找到各种xpath引擎的差异,在哪种情况下我应该使用CSS,以及在哪些XPath中,如果我使用的是IE。 谢谢。

如何使用selenium或webdriver处理测试自动化中的文件上载

我认为每个人如何使用Webdriver进行测试自动化必须意识到它对Web开发的巨大优势。 但是,如果文件上传是您的Webflow的一部分,则存在一个巨大的问题。 它不再是测试自动化。 浏览器的安全限制(调用文件选择)实际上使得无法自动化测试。 Afaik唯一的选择是让webdriver单击文件上传按钮,睡眠线程,让开发人员/测试人员手动选择文件,然后完成其余的Web流程。 如何解决这个问题,是否有解决方法呢? 因为它真的不能这样做。 这没有意义。 这是我所知道的浏览器安全限制不适用的唯一情况: function window.onload(){ document.all.attachment.focus(); var WshShell=new ActiveXObject(“WScript.Shell”) WshShell.sendKeys(“D:\MyFile.doc”) }

如何解决,陈旧元素exception? 如果元素不再附加到DOM?

我有一个关于“元素不再附加到DOM”的问题。 我尝试了不同的解决方案,但他们间歇性地工作。 请建议一个永久性的解决方案。 WebElement getStaleElemById(String id, WebDriver driver) { try { return driver.findElement(By.id(id)); } catch (StaleElementReferenceException e) { System.out.println(“Attempting to recover from StaleElementReferenceException …”); return getStaleElemById(id, driver); } } WebElement getStaleElemByCss(String css, WebDriver driver) { try { return driver.findElement(By.cssSelector(css)); } catch (StaleElementReferenceException e) { System.out.println(“Attempting to recover from StaleElementReferenceException …”); return getStaleElemByCss(css, driver); } catch […]

如何使用selenium webdriver在chrome中下载pdf文件

我想使用selenium在chrome中下载pdf。 System.setProperty(“webdriver.chrome.driver”, System.getProperty(“user.dir”) + System.getProperty(“file.separator”) + “BrowserDrivers” + System.getProperty(“file.separator”) + “chromedriver.exe”); String downloadFilepath = “C:\\Users\\Vinod\\Downloads”; HashMap chromePrefs = new HashMap(); chromePrefs.put(“profile.default_content_settings.popups”, 0); chromePrefs.put(“download.default_directory”, downloadFilepath); //Save Chrome Opions ChromeOptions options = new ChromeOptions(); HashMap chromeOptionsMap = new HashMap(); options.setExperimentalOption(“prefs”, chromePrefs); options.addArguments(“–test-type”); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); cap.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(cap); driver.get(url); […]