firefox浏览器

时间:2017-09-08 09:11:53

标签: selenium

我正在尝试使用selenium webdriver和firebug在firefox浏览器中自动化gmail。

Selenium无法识别密码fileld的xpath。

密码字段的xpath是什么。

7 个答案:

答案 0 :(得分:1)

当您尝试登录 Gmail Account 时,在填写带有文字的 EmailID/Phone 字段并同时点击 Next 按钮, Password 的文本字段需要一段时间才能显示在Viewport内。因此,除了仅为 xpath 字段找到 Password 之外,您必须诱导一些 ExplicitWait ,即 WebDriverWait 如下:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    WebElement password = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']")));
    password.sendKeys("your_password");

答案 1 :(得分:1)

尝试下面提到的xpath:

//*[@name="password"]

我建议您在Chrome浏览器控制台上验证xpath。 如果您的应用程序支持具有以下语法的Chrome

$x("//*[@name='password']")

答案 2 :(得分:0)

尝试以下xpath:

By.xpath(.//*[@id='password']/div[1]/div/div[1]/input)

答案 3 :(得分:0)

使用此xpath:

 //INPUT[@type='password']  

试试这个。 firebug已过时我建议您使用其他软件来处理更复杂的xpath。

答案 4 :(得分:0)

使用此:

//input[@type='password']

否则你可以找到像

driver.findElement(By.name("password"));

答案 5 :(得分:0)

使用以下任何XPath

//input[@type='password']

OR

//input[@name='password']

OR

//input[contains(@aria-label,'Enter your password')]

OR

//input[contains(@autocomplete,'current-password')]

完整的代码如下: -

     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
     driver.findElement(By.name("identifier")).sendKeys("xxx@gmail.com");
     driver.findElement(By.xpath("//span[contains(.,'Next')]")).click();
     driver.findElement(By.name("password")).sendKeys("123456");
     WebDriverWait wait = new WebDriverWait(driver, 10);
     WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[contains(.,'Next')]")));
     element.click();

答案 6 :(得分:0)

使用此xpaths

//input[@class='whsOnd zHQkBf'][@name='password']
//input[@type='password']
//*[@type='password']
//input[contains(@aria-label,'Enter your password')][@name='password']
//input[contains(@aria-label,'Enter your password')][@autocomplete='current-password']

您应该使用xpath,而不是使用name,因为它优先于xpath,如下所示:

System.setProperty("webdriver.chrome.driver", "E:\\software and tools\\chromedriver_win32\\chromedriver.exe");
WebDriver   chrome_driver = new ChromeDriver();
chrome_driver.findElement(By.name("password")).sendKeys("xxxxxxxxxx");

或者您可以使用任何xpath

chrome_driver.findElement(By.xpath("xpath you want")).sendKeys("xxxxxxxxxx");
相关问题