Reputation: 213
Here is my code to click a simple login button on this Website
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Reports {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://platform.drawbrid.ge");
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='_loginButton']")).click();
}
}
I am getting following error:
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 2.05 seconds
Upvotes: 6
Views: 73061
Reputation: 1
You could try:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("your locator value")));
Or
wait.until(ExpectedConditions.ElementIsVisible(By.xpath("your locator value")));
Upvotes: 0
Reputation: 384
You have two buttons with given xpath on this page, first is not visible, thats why you are getting ElementNotVisibleException
One is under <div class="loginPopup">
Second (the one you need) is under <div class="page">
So change your xpath to look like this, and it will fix your problem:
By.xpath("//div[@class='page']//div[@id='_loginButton']")
Upvotes: 17
Reputation: 11
Make sure your window on the remote server
is big enough so the elements are not hidden because of space constraints ..
This worked for me: (I use c#
)
driver.Manage().Window.Size = new System.Drawing.Size(1928, 1060);
Upvotes: 0
Reputation: 1
public static void Listget (WebDriver driver) throws Exception
{
Thread.sleep(5000);
UtilityMethod.getAppLocaters(driver, "closeicon").click();
Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("//li[@class='parent dropdown aligned-left']"));
Thread.sleep(5000);
action.moveToElement(we).build().perform();
List<WebElement>links = driver.findElements(By.xpath("//span[@class='menu-title']"));
int total_count = links.size();
System.out.println("Total size :=" +total_count);
for(int i=0;i<total_count;i++)
{
WebElement element = links.get(i);
String text = element.getAttribute("innerHTML");
System.out.println("linksnameis:=" +text);
try{
File src = new File("D:ReadFile.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sh = wb.getSheetAt(0);
sh.createRow(i).createCell(1).setCellValue(text);
FileOutputStream fos = new FileOutputStream(new File("D:/ReadFile.xlsx"));
wb.write(fos);
fos.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
}
Upvotes: 0
Reputation: 331
Webdriver
may throw an ElementNotVisible
exception in-case there are multiple elements with the same locator and if Webdriver
has already operated upon one of the element matching the locator.
In such scenarios you can first get the size of the element using
int var_ele_size= driver.findElements(By.xpath("locator")).size();
and then take the first element from the list and click on the element.
driver.findElements(By.xpath("locator")).get(var_ele_size-1).click();
Upvotes: 0
Reputation: 51
There are 3 occurrences of id="_loginButton"
.
Used the id="_loginButton"
under class="signIn"
by cssSelector to get the exact button in the page.
By.cssSelector("div.signIn div#_loginButton")
Upvotes: 2
Reputation: 473763
There are even 3 elements with id="_loginButton"
on the page, and only one is visible - the one located inside the login form, you can get it by a CSS selector:
By.cssSelector("form#_loginForm div#_loginButton")
Upvotes: 3