user3413540
user3413540

Reputation: 49

Selenium cannot find element

Having some issues using Selenium web driver in Chrome.

My goal is to give the user ~15-30 seconds to log in on there own and then start doing automated testing.

The problem is after I click the login button and go to the next page, I am not able to find elements by xpath, id, etc.

public static void runTest() throws InterruptedException {

    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.url.com");
    driver.manage().window().maximize();
    Thread.sleep(15000);
    driver.findElement(By.xpath("//*[@id=\"content-main\"]/div/div/form/div/p/input")).click();

    System.out.println("User has logged in and it has found element for Attachment Upload.");
    Thread.sleep(15000);

    driver.findElement(By.xpath("//*[@id=\"invoiceMenu\"]/a")).click();
}

I have also tried using explicit waits and have had no luck for example:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("someid")));

The error I am usually getting back is:

Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //*[@id="invoiceMenu"]/a (tried for 10 second(s) with 500 milliseconds interval)

Edit:

Was able to get some of the elements (angular ones) working with a few plugins for Chrome. Element Locator and ChroPath worked fantastic. Took some playing around with, but once I got one I was able to piece together the rest of them.

Upvotes: 0

Views: 1890

Answers (1)

Larry
Larry

Reputation: 226

I would suggest that you open the chrome console on your browser and try to interact with the element in question e.g. using:

document.getElementById('someId').click()

If you are able to click on the element like that, then you can use javascript executor in your code as follows:

((JavascriptExecutor)driver).executeScript("document.getElementById('someId').click();");

Upvotes: 1

Related Questions