0

I am trying to login using selenium.

<form id="main-login-form" class="login-form form-container">
<input       name="username" id="username-input" placeholder="Username"   class="form-input"    autofocus="">

I am using the code.

  import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*; import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Tables {

public static void main(String[] args) {
    // Create a new instance of the html unit driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new HtmlUnitDriver();
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // And now use this to visit Google
    driver.get("https://focus.nassau.k12.fl.us/focus/");


    // Find the text input element by its name
    WebElement element = driver.findElement(By.xpath("//input[@id='username-input']"));
    element.sendKeys("mcdonaldje");



    System.out.println(driver.getCurrentUrl());

    // Now submit the form. WebDriver will find the form for us from the element


    driver.quit();
}

I keep getting this error

 Exception in thread "main" org.openqa.selenium.NoSuchElementException:
 Unable to locate a node using //input[@id='username-input']
 For documentation on this error, please visit:      
 http://seleniumhq.org/exceptions/no_such_element.html
 Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'

2 Answers2

0

You are doing it right!

In [16]: from selenium import webdriver

In [17]: driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)

In [18]: driver.get("https://focus.nassau.k12.fl.us/focus/");

In [19]: el = driver.find_element_by_xpath("//input[@id='username-input']")

In [20]: el.send_keys("mcdonaldje")

In [21]: driver.current_url
Out[21]: u'https://focus.nassau.k12.fl.us/focus/'
drets
  • 2,583
  • 2
  • 24
  • 38
  • It doesn't like line 17. `driver = webdriver.Remote(DesiredCapabilities.chrome());` Saying `webdriver` can not be resolved. – Jesse McDonald Dec 07 '15 at 22:37
  • You are writing on Java bindings, my answer is written in python. I just shown you that there is no problem with finding element using xpath. – drets Dec 07 '15 at 22:43
0

After hitting the URL please wait for it load all the elements so that your web element is displayed on the page. Any wait condition after driver.get("https://focus.nassau.k12.fl.us/focus/"); works well.

Chandra Shekhar
  • 664
  • 2
  • 9
  • 24