Tag: selenium webdriver

通过多个类名来查找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框选项并且服务器重定向到下一个密码页面。 我想问一下我将做什么,以便我的密码只能输入密码页面。

如何按Ctrl + A选择Selenium WebDriver使用Java选择页面中的所有内容

我想通过使用WebDriver with Java在键盘上按Ctrl + a来选择所有内容。 我写了以下代码: Actions actionObj = new Actions(driver); actionObj.keyDown(Keys.CONTROL) .sendKeys(Keys.chord(“A”)) .keyUp(Keys.CONTROL) .perform(); 不幸的是,它没有用。 我的WebDriver Java代码有什么问题?

你如何在用java编写的selenium webdriver程序中使用firefox插件?

我试图运行一个selenium脚本,点击我的工具栏中的一个firefox插件。 是否有可能做到这一点?

参数WebElement中的方法sendKeys(CharSequence )不适用于参数(String)

我试图将一个字符串发送到sendkeys()方法,但它不接受并抛出错误 我的代码如下: package healthcare; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; import com.thoughtworks.selenium.Selenium; import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; public class MailRegister_Webdriver { public WebDriver driver; public Selenium selenium; public void openURL(){ //System.setProperty(“webdriver.chrome.driver”, “F:\\Library\\chromedriver.exe”); driver=new FirefoxDriver(); selenium=new WebDriverBackedSelenium(driver, “http://mail.in.com”); driver.get(“http://mail.in.com”); } public void register() throws Exception{ //driver.findElement(By.cssSelector(“input.registernow”)).click(); selenium.click(“css=input.registernow”); Thread.sleep(3000); driver.findElement(By.id(“fname”)).sendKeys(“Nagesh”); selenium.select(“day”, “10”); selenium.select(“month”, “Jun”); new Select(driver.findElement(By.id(“year”))).selectByVisibleText(“1999”); […]

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

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

如何使用selenium在PhantomJS中设置代理身份validation?

我在java中运行这个简单的selenium测试: public static void main(String[] args){ WebDriver driver = new PhantomJSDriver(); driver.get(“http://www.google.com”); WebElement element = driver.findElement(By.id(“gbqfif”)); element.sendKeys(“cheese”); element.submit(); System.out.println(“Titulo:”+driver.getTitle()); driver.quit(); } 但在我的办公室,它需要代理身份validation,我不知道如何设置它。 我必须把我的用户和密码放在某个地方。 你能帮我吗?

设置Firefox配置文件以使用Selenium和Java自动下载文件

我想使用Selenium webdriver和Javavalidation文件下载。 要下载的文件是pdf格式。 当webdriver点击AUT中的“下载”链接时,firefox会打开以下下载确认窗口 我希望firefox自动下载文件而不显示上面的确认窗口,所以我使用了下面的代码 FirefoxProfile firefoxProfile=new FirefoxProfile(); firefoxProfile.setPreference(“browser.download.folderList”,2); firefoxProfile.setPreference(“browser.download.manager.showWhenStarting”,false); firefoxProfile.setPreference(“browser.download.dir”,downloadPath); firefoxProfile.setPreference(“browser.helperApps.neverAsk.saveToDisk”,”application/pdf”); WebDriver driver=new FirefoxDriver(firefoxProfile); 但是Firefox仍然显示相同的窗口。 如何设置firefox配置文件以便自动下载PDF文件而不显示确认对话框?

使用Selenium WebDriver和Tor

因为Tor Browser Bundle只是Firefox的补丁版本,所以似乎可以使用带有Tor浏览器的FirefoxDriver 。 这是我到目前为止所尝试的: String torPath = “C:\\Users\\My User\\Desktop\\Tor Browser\\Start Tor Browser.exe”; String profilePath = “C:\\Users\\My User\\Desktop\\Tor Browser\\Data\\Browser\\profile.default”; FirefoxProfile profile = new FirefoxProfile(new File(profilePath)); FirefoxBinary binary = new FirefoxBinary(new File(torPath)); FirefoxDriver driver = new FirefoxDriver(binary, profile); driver.get(“http://www.google.com”); 这会导致一个空白的Tor浏览器页面打开,并显示一条弹出消息: 无法加载您的Firefox配置文件。 它可能丢失或无法访问。 我知道该配置文件是有效/兼容的,因为我可以成功启动浏览器和配置文件: binary.startProfile(profile, profilePath, “”)); 但是,我不知道如何将命令发送到以这种方式打开的浏览器。 我发现了类似的问题,但我特意寻找Java解决方案,最好是在Windows上测试。 我正在使用可在此处下载的独立Selenium库和可在此处下载的Tor Browser Bundle。

在Selenium WebDriver中实现InternetExplorerDriver期间发生NoSuchElementException

目前,我正在研究WebDriver来调用IE浏览器来运行测试。 但是当我尝试运行下面的简单示例时,我收到了NoSuchElementException 。 但是,如果我使用Chrome驱动程序或Firefox驱动程序,代码工作正常。 任何想法或想法将不胜感激。 Jar: selenium-server-standalone-2.5.0.jar 码: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public static void main(String[] args) throws InterruptedException { DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver = new InternetExplorerDriver(ieCapabilities); driver.get(“www.google.com”); driver.findElement(By.name(“q”)); } 错误信息: Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to find element with name == q (WARNING: The server […]