Selenium Twitter java Selenium Twitter java selenium selenium

Selenium Twitter java


Found that By inspecting the DOM of the twitter login page has two forms having almost same properties and three username and password fields are found.That's why you're getting ElementNotVisibleException[See Image]

enter image description here

So for that you have to go with relative xpath or css selectors or implement a logic for that .I'm proving two ways you can handle that situation

And I don't know why you are iterating over all the input fields and then finding the element by checking its attributes.You can simply call driver.findElements(By.name())

Relative Xpath

As I found that the input inside the @class signin-wrapper is the visible one,I've gone for this xpath

driver.get("https://twitter.com/login/");driver.findElement(By.xpath("//div[@class='signin-wrapper']//input[@name='session[username_or_email]']")).sendKeys("viaxpath");driver.findElement(By.xpath("//div[@class='signin-wrapper']//input[@name='session[password]']")).sendKeys("viaxpath");

Get the Visible Element

As the name implies it will find all the elements and return the element that is only visible

driver.get("https://twitter.com/login/"); getVisibleElement(driver, "session[username_or_email]").sendKeys("viavisibleName"); getVisibleElement(driver, "session[password]").sendKeys("viavisibleName");public static WebElement getVisibleElement(WebDriver driver, String name) {    List<WebElement> elements = driver.findElements(By.name(name));    for (WebElement element : elements) {        if (element.isDisplayed()) {            return element;        }    }    return null;}