DBInsight Code Issue | Selenium Forum
M
Posted on 23/10/2016
Hi Ashish,

My code is failing getting time out. Please help & suggest.

I tried to to use implicit and explicit wait but still the code is failing.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;


public class Login {

@Test

public void login (){

WebDriver d1= new FirefoxDriver();
d1.get("https://www.dbinsight.com/dbinsight");

WebDriverWait wait=new WebDriverWait(d1,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='user']")));

WebElement b=wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath("//*[@id='user']")));

/*d1.findElement(By.xpath("//*[@id='user']")).sendKeys("test1@gmail.com");
d1.findElement(By.xpath("//*[@id='password']")).sendKeys("A");*/
d1.findElement(By.xpath("html/body/div[1]/div[1]/a[1]")).click();

System.out.println(d1.getTitle());

}


}
------------------------

FAILED: login
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.xpath: //*[@id='user']
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Sandeep', ip: '192.168.0.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_73'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 68ad655b-0957-42bc-97b1-ac0b51461521
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:261)
at Login.login(Login.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:823)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:778)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1225)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1150)
at org.testng.TestNG.runSuites(TestNG.java:1075)
at org.testng.TestNG.run(TestNG.java:1047)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath"

M
Replied on 24/10/2016

[quote:1fw1k8zg]NoSuchElementException: Unable to locate element:[/quote:1fw1k8zg]
it is very common error

1.)this error could come because xpath is wrong or
2.)it can come because you didn't use a wait statement.

please take a look at this q/a for more info

http://stackoverflow.com/questions/27227538/org-openqa-selenium-nosuchelementexception-unable-to-locate-element

http://stackoverflow.com/questions/20461088/selenium-web-driver-is-unable-to-locate-element


M
Replied on 24/10/2016

I have tried both explicit and explicit wait, also my xpath is correct, please help .

I am unable to determine what exactly is missing.


M
Replied on 25/10/2016

user id is in iFrame. you'll have to use switchto statement.