I am facing an issue with selenium that I could not solve.
I am getting the following error"
no such element: Unable to locate element:{"method":"id","selector":"menu-supply-approval-queue"}
I know that that the issue is to wait.
So I made the next method:
public static WebElement getWebElementByIdWithWait(String id)
{
WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));
return WebDriverMgr.waitForElementToBeClickable(By.id(id));
}
However selenium not waits, and get this error again:
Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}
(Session info: chrome=76.0.3809.132)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Can someone please advise how to make selenium to wait for the element to be displayed/clickable.
it is not waiting a second
what is more odd is that selenium actually returned the element and then clicks on it, so If he can not find it how he returned it? it just mess with the logs
Here is code that works, however it uses sleep
public static WebElement getWebElementByIdWithWait(String id)
{
Logger.sleep(60000);
// WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 8);
// wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));
return WebDriverMgr.waitForElementToBeClickable(By.id(id));
}
regards
This error message...
Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}
(Session info: chrome=76.0.3809.132)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.36
Release Notes of chromedriver=2.36 clearly mentions the following :
Supports Chrome v63-65
You are using chrome=76.0
Release Notes of ChromeDriver v76.0 clearly mentions the following :
Supports Chrome version 76
Your JDK version is 1.8.0_65 which is pretty ancient.
So there is a clear mismatch between the JDK v8u65 , ChromeDriver v2.36 and the Chrome Browser v76.0
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
ChromeDriver is updated to current ChromeDriver v77.0 level.
Chrome is updated to current Chrome Version 77.0 level. (as per ChromeDriver v77.0 release notes)
Execute your #Test as non-root user.
There is an expected condition elementToBeClickable
WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 60);
wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-supply-approval-queue")));
I'm not sure where/what the waitForElementToBeClickable call is doing and why it might be failing.
The method you posted has a String parameter of id but you hard coded a wait for a specific ID in the second line
public static WebElement getWebElementByIdWithWait(String id)
{
WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));
^ this is hardcoded
return WebDriverMgr.waitForElementToBeClickable(By.id(id));
}
Have you tried removing that line?
public static WebElement getWebElementByIdWithWait(String id)
{
WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id));
}
If it were me, I would use a method like the below. It's not specific to IDs (you pass in a By so it can be used with IDs, CSS selectors, XPath, etc.) and it takes care of the click for you so the wait is specific to clickable.
public static void click(By locator)
{
new WebDriverWait(WebDriverMgr.getDriver(), 15).until(ExpectedConditions.elementToBeClickable(locator)).click();
}
You would call it like
click(By.id("menu-supply-approval-queue"));
Maybe you can try "Thread.Sleep(1000);" like
After investigation I found the issue, the Implicit wait was too small.
the soloution:
Related
Code is working fine for chrome but for Edge I'm facing issue
I have set below properties in application.properties file
driver.name=edgeDriver
webdriver.edge.driver = drivers/msedgedriver.exe
I have also downloaded edgedriver.exe as per current version of my edge browser
Edge Version : Version 89.0.774.63
When I am trying to execute the test I am seeing below messages in console log
Unable to get class
com.qmetry.qaf.automation.step.client.TestStepExporter from jar
/C:/Users/piyush/.m2/repository/com/qmetry/qaf/3.0.0/qaf-3.0.0.jar
[QAFTestBase] - Initializing
Driver...browser_str:edgeDriver,base_url:https://qmetry.github.io/qaf/,sel_server:localhost,port:4444
[UiDriverFactory] - Driver: edgeDriver Mar 26, 2021 3:25:36 PM
org.openqa.selenium.remote.DesiredCapabilities edge INFO: Using new EdgeOptions() is preferred to DesiredCapabilities.edge()
Unable to create driver instance in 1st attempt with retry timeout of
30 seconds. You can check/set value of 'driver.init.retry.timeout'
appropriately to set retry timeout on driver initialization
failure.Unable to Create Driver Instance for edge:
java.lang.NoSuchMethodException:
org.openqa.selenium.edge.EdgeDriver.(java.net.URL,
org.openqa.selenium.Capabilities)
Build info: version: '3.141.59', revision: 'e82be7d358', time:
'2018-11-14T08:17:03'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version:
'10.0', java.version: '11.0.10'
Driver info: driver.version: unknown
Referred to how to use edgeDriver with qaf
it seems the property webdriver.edge.driver should be appended with "system" prefix. That means:
system.webdriver.edge.driver = drivers/msedgedriver.exe
After this, Page launched successfully
Not able to click on any button in the application.
Error stack trace:
org.openqa.selenium.ElementNotVisibleException: element not interactable
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z'
System info: host: 'SHIPAWAR-54Q9D', ip: '10.65.75.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
I tried java script executor, actions class but none of them worked
public void clickHERE(String deal) throws Throwable{
javaScriptClick(driver, HERE);
driver.findElement(By.xpath(enterDeal)).sendKeys(deal);
Thread.sleep(5000);
int ok_size=driver.findElements(By.cssSelector("[name=SearchDeal]")).size();
System.out.println("the search button size:" +ok_size);
driver.findElement(By.xpath(enterDeal)).sendKeys(Keys.ENTER);
Thread.sleep(5000);
scrollToElement(driver, nextTabDealInfo);
driver.findElement(By.xpath(nextTabDealInfo)).click(); // this button in not working
}
should be able to click the button.
nextTabDealInfo is the xpath:
//*[#type='button' and contains(#value,'Next Tab')]
HTML for button:
<input type="button" name="fromOptyInfoTab" value="Next Tab >" onclick="return switchTabs('nonStandardInfo.do');" class="buttonNextTab">
This error message...
org.openqa.selenium.ElementNotVisibleException: element not interactable
.
System info: host: 'SHIPAWAR-54Q9D', ip: '10.65.75.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
...implies that the ChromeDriver was unable to communicate with the Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Your Selenium Client version is 3.10.0 of 2018-03-02T19:03:16.397Z which is almost an year older.
Your JDK version is 1.8.0_60 which is pretty old and ancient.
So there is a clear mismatch between the JDK v8u60 , Selenium Client v3.10.0
Solution
Upgrade JDK to recent levels JDK 8u202.
Upgrade Selenium to current levels Version 3.141.59.
could anyone please tell me , why i get timeout out issue intermittently while sign in on web page after browsing the URL . i get it intermittently , it works fine after i close all the web browser and run the program . the below error message , i want to know the root cause , can anyone help me please !
FAILED CONFIGURATION: #BeforeTest setup
org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.1.7601 SP1 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: '01HW596115', ip: '10.29.124.26', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
This error message...
FAILED CONFIGURATION: #BeforeTest setup
org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.1.7601 SP1 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: '01HW596115', ip: '10.29.124.26', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.42
Release Notes of chromedriver=2.42 clearly mentions the following :
Supports Chrome v68-70
You are using chrome=71.0
Release Notes of ChromeDriver v2.45 clearly mentions the following :
Supports Chrome v70-72
So there is a clear mismatch between the ChromeDriver v2.42 and the Chrome Browser v71.0
Solution
Upgrade ChromeDriver to current ChromeDriver v2.45 level.
Keep Chrome version between Chrome v70-72 levels. (as per ChromeDriver v2.45 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
When I run my tests on Chrome I often get a WebdriverException that Chrome is not reachable. It doesn't happen every time. Maybe once every 15 times. I am having to run everything on Windows machines and I have the latest Chrome, Chromedriver, Selenium-Webdriver versions.
I've tried setting the environmental variable "DBUS_SESSION_BUS_ADDRESS=/dev/null". Doesn't help at all.
Anyone come across this and found a solution?
org.openqa.selenium.WebDriverException: chrome not reachable
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 62.52 seconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'CORPMNA7158A', ip: '10.26.195.163', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
The error does gives us some hint as follows :
org.openqa.selenium.WebDriverException: chrome not reachable
Which essentially implies that chromedriver binary is unable to spawn a new Chrome Browser process.
Your main issue is the version compatibility among the binaries you are using as follows :
You are using chromedriver=2.35.528161 (released 2018-01-10)
Release Notes of chromedriver=2.35 clearly mentions the following :
Supports Chrome v62-64
You mentioned of using latest Chrome. I suppose it is chrome=65.x
You are using Selenium Version 2.52.0 (released 2016-02-11 11:22:43) [as per the error stack trace within your question]
So the time gap between the release of Selenium Version 2.52.0 and chromedriver=2.35.528161 is almost 2 Years and are not compatible. Hence ChromeDriver is unable to spawn the new Chrome Browser process at times.
Solution
Keep the ChromeDriver at v2.35 level.
Downgrade Chrome to stable Chrome v64.x levels. (as per ChromeDriver v2.35 release notes)
Upgrade Selenium to current levels Version 3.8.1.
Execute your Test.
I have an application that uses Selenium Webdriver to get some information from a site. It works fine with FirefoxDriver and ChromeDriver, but when I tried to switch to PhantomJSDriver, I encountered some difficulties.
On a Windows machine , it starts normally, then immediately begins spitting out the following lines over and over again:
Jan 05, 2014 7:28:43 PM org.apache.http.impl.client.DefaultRequestDirector tryEx
ecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
This is repeated probably several hundred times for about 10 minutes until it finally loads the page; sometimes it doesn't even manage to load it at all.
On a Linux machine, it tries to start, then returns the following:
Exception in thread "thread1"
org.openqa.selenium.remote.UnreachableBrowserException: Could not
start a new session. Possible causes are invalid address of the remote
server or browser start-up failure. Build info: version: 'unknown',
revision: 'unknown', time: 'unknown' System info: host: 'pangolin',
ip: '128.238.32.20', os.name: 'Linux', os.arch: 'amd64', os.version:
'2.6.32-39-generic', java.version: '1.7.0' Driver info:
driver.version: PhantomJSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:107)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:96)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver
server to start. Build info: version: 'unknown', revision: 'unknown',
time: 'unknown' System info: host: 'pangolin', ip: '128.238.32.20',
os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-39-generic',
java.version: '1.7.0' Driver info: driver.version: PhantomJSDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 7 more Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting
for [http://localhost:16050/status] to be available after 20002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 9 more Caused by: com.google.common.util.concurrent.UncheckedTimeoutException:
java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
... 10 more Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:258)
at java.util.concurrent.FutureTask.get(FutureTask.java:119)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 11 more
What am I doing wrong? I've read a lot about how Phantomjs is so much faster than the other drivers, and would really like to use it, but if it takes 10 minutes to load each page, that's obviously not feasible.
I am running Selenium WebDriver version 2.38.0 and Phantomjs version 1.9.2.
Thank you very much in advance,
bsg
EDIT
Just to clarify, I don't think this has anything to do with my code; the errors on Linux are being thrown on the line where I try to start the PhantomJS driver, below.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
phantombinary//"/home/p/phantomjs-1.9.2-linux-x86_64/bin/phantomjs"
);
// Launch driver (will take care and ownership of the phantomjs process)
WebDriver driver = new PhantomJSDriver(caps);
System.out.println("starting driver");
If it is still not working for you on Linux, try below piece of code, it is working for me on Mac.
capabilities.setCapability("phantomjs.binary.path", "path of phantom binary/phantomjs")
org.openqa.selenium.remote.UnreachableBrowserException clearly something to do with Phantom. On Windows ensure Phantom is running (Set Environment variable and add PATH)
Check that Remote Machine hub address is correct and you should be able to run phantomjs.
Note: Selenium Server must be running on the desired remote machine.
DesiredCapabilities phantomBeast = DesiredCapabilities.phantomjs();
try {
webDriverInstance = new RemoteWebDriver(new URL(hubUrl), phantomBeast);
} catch (Exception e) {
//Do something
}