Getting "element not interactable" for below code - selenium

I am trying to click on few elements using below code on one webpage but it gives element is not interactable error. I also applied wait condition but it didn't help.
Here is my code:
driver.get("https://www.cleartrip.com/flights/results?from=BDQ&to=PNQ&depart_date=13/04/2019&adults=1&childs=0&infants=0&class=Economy&airline=&carrier=&intl=n&sd=1555000238907&stops=1&departureTime=0_8");
driver.findElement(By.xpath("//input[#value='1' and #name = 'stops']")).click();
driver.findElement(By.xpath("//input[#value='2' and #name = 'stops']")).click();
driver.findElement(By.xpath("//input[#value='0_8' and #name = 'departureTime']")).click();
error :
FAILED: testFlightSearch
org.openqa.selenium.ElementNotVisibleException: element not interactable
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'DESKTOP-B0K7HHH', ip: '192.168.43.195', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.20 (8e2b610813e16..., userDataDir: C:\Users\shakti\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:62726}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.86, webStorageEnabled: true}
Session ID: 8931562f8f37533e51073920887d83b0

The elements that you are trying the click are present on the page but are not clickable/interactable and that's the reason you are getting element not interactable exception.
You need to pick elements by using the xpath mentioned below and it would work:
driver.get("https://www.cleartrip.com/flights/results?from=BDQ&to=PNQ&depart_date=13/04/2019&adults=1&childs=0&infants=0&class=Economy&airline=&carrier=&intl=n&sd=1555000238907&stops=1&departureTime=0_8");
driver.findElement(By.xpath("//label[#for='1_1_1']")).click();
driver.findElement(By.xpath("//label[#for='1_1_2']")).click();
driver.findElement(By.xpath("//label[#for='1_1_0_8_departureTime']")).click();

The reason why you are getting org.openqa.selenium.ElementNotVisibleException is because when selenium goes to that URL, there is a progress bar on top of page which is still loading contents of the page. While it is loading, your code is searching for first element to click but it has not yet been loaded in the DOM.
You need to wait for the progress bar to complete loading before triggering the element click. The progress bar when loading has xpath: //p[#class='loadState tCenter' and contains(text(), 'Getting prices and availability...')] and after loading completely, the xpath to look for is //p[#class='loadState tCenter' and contains(text(), 'Your search results are ready.')].
Add a wait for element to appear for the 2nd xpath above and once it is visible, then trigger the element click.

Related

Selenium Checkbox cannot find - web driver Expected condition failed: waiting for visibility of element located by By.xpath:

I am trying to use selenium for headless browser to trigger some input but one of the checkbox in the page is not able to identify. I tried with waiting 100 seconds, and without waiting, but still having the same error that element cannot find.
Below is the code. I tried with ID and xPath, both having the same error. Also with visibilityOfElementLocated and elementToBeClickable but same error.
When I try the xpath in the chrome inspect element, it finds only one element. So I think xpath is correct.
val wait = WebDriverWait(driver, 30)
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#name = 'element_ID']")))
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#name = 'element_ID']")))
val elem: WebElement = driver.findElement(By.xpath("//*[#id = 'element_ID']"))
elem.click()
Error
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element
to be clickable: By.xpath: //*[#name = 'element_ID'] (tried for 30 second(s) with 500 milliseconds interval)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.4', java.version: '1.8.0_321'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.38.552518 (183d19265345f5..., userDataDir: /var/folders/06/072_bdvx0rs...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 103.0.5060.53, webStorageEnabled: true}
Session ID: 2d1c4aab1e9780033abcd6891537a5dsf

clear() method doesn't clears the field in MS EDGE IE11 with Selenium-4.1.2

Recently, I have upgraded my Selenium version from 2.53 to 4.1.2 to enable testing of our application on MS EDGE IE11. But we are continuously facing issue when we are clearing any TextBox field using simple Selenium .clear(). Although, its clearing that respective and but also throwing below exception.
Did anyone else facing similar kind of issues with Selenium-4.1.2 ?
Exception:
org.openqa.selenium.InvalidElementStateException: A JavaScript error
was encountered clearing the element. The driver assumes this is
because the element is hidden, disabled or read-only, and it must not
be to clear the element. Build info: version: '4.1.2', revision:
'9a5a329c5a' System info: os.name: 'Windows 10', os.arch: 'amd64',
os.version: '10.0', java.version: '1.8.0_222' Driver info:
org.openqa.selenium.ie.InternetExplorerDriver Command:
[69d06b0b-b468-455b-9d3c-24626ad40e16, clearElement
{id=2bb89cb8-5d24-4dd8-8e3a-be8fa7e1272e}] Capabilities
{acceptInsecureCerts: false, browserName: internet explorer,
browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal,
platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(),
se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0,
enablePersistentHover: true, ie.browserCommandLineSwitches: ,
ie.edgechromium: false, ie.edgepath: , ie.ensureCleanSession: false,
ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false,
ignoreProtectedModeSettings: false, ignoreZoomSetting: false,
initialBrowserUrl: http://localhost:54726/, nativeEvents: true,
requireWindowFocus: false}, setWindowRect: true,
strictFileInteractability: false, timeouts: {implicit: 0, pageLoad:
300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Element: [[InternetExplorerDriver: internet explorer on WINDOWS
(69d06b0b-b468-455b-9d3c-24626ad40e16)] -> id: userid] Session ID:
69d06b0b-b468-455b-9d3c-24626ad40e16 at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:251)
at
org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:126)
Expectation : We expect clear() should clear the field without throwing any exception.
This is due to a bug in the Edge IE mode driver
https://github.com/SeleniumHQ/selenium/issues/10488
A possible workaround would be to use JavascriptExecutor to locate and clear the input field
JavascriptExecutor jsExec = (JavascriptExecutor)driver;
jsExec.executeScript("document.getElementById('field_to_clear').value=''");
InvalidElementStateException indicates that a WebElement is in a certain state in which actions cannot be performed with it. A couple of examples would include an element being obscured by another when clicking, or perhaps not being visible on the DOM.
Solution
It is always recommened that to clear any <input> field you need to induce WebDriverWait to elementToBeClickable() for the element (JavaScript) to render the HTML DOM completely before you invoke click() as follows:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("element_cssSelector"))).clear();

Not navigating pagination3 and getting stale element exception

I need to navigate pages and check services on each page down or up, but while navigating page 3 is showing error message as stale element exception.
I have tried with this code but it's not working fine , someone please help me on this.
public class TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer {
public static void TC_2377154_12236() {
try {
Assert.done("Start -> TC_2377154_12236");
//BaseSetUp.openBrowser();
WebDriver driver = FrameworkDriver.driver;
driver.get("https://webtech.humana.com/nes/servicesview.aspx");
Assert.assertTrue(driver.findElement(By.xpath("//input[#id='tbLBVServerName']")).isDisplayed(), "LBV Server name is displayed");
driver.findElement(By.xpath("//input[#id='tbLBVServerName']")).sendKeys("SRS");
Assert.assertTrue(driver.findElement(By.xpath("//input[#id='btnFilter']")).isDisplayed(),"Filter button is displayed");
driver.findElement(By.xpath("//input[#id='btnFilter']")).click();
Assert.assertTrue(driver.findElement(By.xpath("//table[#id='dgServices']")).isDisplayed(),"Services name table is Displayed");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until( ExpectedConditions.presenceOfElementLocated(
By.xpath("//a[#style='color:Black;']")));
List<WebElement> pagination = driver.findElements(By.xpath("//a[#style='color:Black;']"));
int s = pagination.size()/2;
System.out.println(s +"Pagination list");
for(int i=0;i<=s;i++){
List<WebElement> ls = driver
.findElements(By
.xpath("//font[#color='red']"));
System.out.println(ls.size()+"list of Down services size");
if (ls.size() > 1)
Assert.fail("All service states are expected Up and Running but there are "+(ls.size()+" servers are down"));
else if (ls.size() == 0)
Assert.fail("****Some technical issue or No Server is up or running****");
else if (ls.size() == 1)
Assert.pass("~~All Servers are Up and running~~");
Thread.sleep(5000);
// ls.get(i).click();
// Thread.sleep(5000);
System.out.println( pagination.get(i));
//driver.findElement(By.xpath("//a[#style='color:Black;']")).click();
pagination.get(i).click();
Thread.sleep(5000);
}
Assert.done("End -> TC_2377154_12236");
} catch (Exception e) {
Assert.error(e, "Error -> TC_2377154_12236");
}
}
}
I expected output as it should click on each and every page , but getting below error
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : PASS - Filter button is displayed
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : PASS - Services name table is Displayed
7Pagination list
5list of Down services size
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : FAIL - All service states are expected Up and Running but there are 5 servers are down
[[ChromeDriver: chrome on XP (4f932cb86e8057b5ecda92c582500243)] -> xpath: //a[#style='color:Black;']]
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : FAIL - Error -> TC_2377154_12236. Error:stale element reference: element is not attached to the page document
(Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 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/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243 Stack Trace: [Ljava.lang.StackTraceElement;#18d3f76
FAIL Error:stale element reference: element is not attached to the page document
(Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 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/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243 Stack Trace:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 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/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at com.humana.hss.scripts.TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer.TC_2377154_12236(TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer.java:54)
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:498)
at com.dell.acoe.framework.run.ExecutionThread.run(ExecutionThread.java:33)
Executing method [TC_2377154_12236]... completed
There is an issue while updating the script status to excel report. Please check file:null
Total:2
Passed:1 50%
Custom Report Generator is configured as:
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : DONE - Custom Report Generator is configured as:
is not a valid CustomReportGenerator, it needs package.Class.method format and with two String args
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : DONE - is not a valid CustomReportGenerator, it needs package.Class.method format and with two String args
Don't retrieve multiple elements out of For Loop.
You should find each element in For Loop again.
WebElement pag = diver.findElement(By.xpath("(//a[#style='color:Black;'])["+(i+1)+"]"));
Xpath example (you can search in web console):
(//a[#style='color:Black;'])[1]
List<WebElement> pagination = driver.findElements(By.xpath("//a[#style='color:Black;']"));
int s = pagination.size()/2;
System.out.println(s +"Pagination list");
for(int i=0;i<=s;i++){
// Add this line
WebElement pag = diver.findElement(By.xpath("(//a[#style='color:Black;'])["+(i+1)+"]"));
List<WebElement> ls = driver.findElements(By.xpath("//font[#color='red']"));
System.out.println(ls.size()+"list of Down services size");
if (ls.size() > 1)
Assert.fail("All service states are expected Up and Running but there are "+(ls.size()+" servers are down"));
else if (ls.size() == 0)
Assert.fail("****Some technical issue or No Server is up or running****");
else if (ls.size() == 1)
Assert.pass("~~All Servers are Up and running~~");
Thread.sleep(5000);
// ls.get(i).click();
// Thread.sleep(5000);
System.out.println( pagination.get(i));
//driver.findElement(By.xpath("//a[#style='color:Black;']")).click();
// Modify this line
pag.click();
Thread.sleep(5000);
}

Unable to click two continue SPAN buttons with Selenium WebDriver

I am trying to click two buttons with the following HTML Code
1.
<span translate="Resources.AddOns.TravelInsurance.Button_ContinueBooking" class="ng-scope">Continue Booking</span>
The Xpath = //*[#id="cont_to_ins"]/span
<button wn-validation-dom="prepaidcards-details" class="orange-btn btn btn-sm bold ng-scope" ng-if="!areOtherAddOnsAfterPrepaidCardsIndexAvailableInAccordion()" id="cont_to_ins" ng-click="continueBooking()"><span translate="Resources.AddOns.PrepaidCards.Button_ContinueBooking" class="ng-scope">Continue Booking</span> <i class="material-icons "></i></button>
The Xpath =
//*[#id="cont_to_ins"]
I have tried several codes but getting error that the button cannot be clicked .
Please kindly assist with the code to Find this element and click to move to next page
driver.findElement(By.xpath("//span[contains(text(), 'Continue Booking')])[1]/following::button[1]")).click();
log.debug("Click Continue ");
WebElement elementa= driver.findElement(By.xpath("//span[text()='Continue Booking']/"));
JavascriptExecutor executore = (JavascriptExecutor) driver;
executore.executeScript("arguments[0].click();", elementa);
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable
to locate an element with the xpath expression //span[contains(text(),
'Continue Booking')])[1]/following::button[1] because of the following
error: SyntaxError: Failed to execute 'evaluate' on 'Document': The
string '//span[contains(text(), 'Continue
Booking')])[1]/following::button[1]' is not a valid XPath expression.
(Session info: chrome=74.0.3729.157) (Driver info:
chromedriver=74.0.3729.6
(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Windows
NT 10.0.17763 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/invalid_selector_exception.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'WN-HQ-LT-DEV-42', ip: '10.10.11.250', os.name:
'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_211' Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false,
applicationCacheEnabled: false, browserConnectionEnabled: false,
browserName: chrome, chrome: {chromedriverVersion: 74.0.3729.6
(255758eccf3d24..., userDataDir: C:\Users\ADEYIN~1.ALA\AppDa...},
cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions:
{debuggerAddress: localhost:64341}, handlesAlerts: true,
hasTouchScreen: false, javascriptEnabled: true,
locationContextEnabled: true, mobileEmulationEnabled: false,
nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy:
normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable:
false, setWindowRect: true, strictFileInteractability: false,
takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit:
0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore,
unhandledPromptBehavior: ignore, version: 74.0.3729.157,
webStorageEnabled: true} Session ID: aebe53b2f0ce483db0acf2034848ecd9
*** Element info: {Using=xpath, value=//span[contains(text(), 'Continue Booking')])[1]/following::button[1]}
Use WebdriverWait to handle dynamic element and following Xpath.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath('//button[#id="cont_to_ins"]/span[contains(.,"Continue Booking")]')));
element.click()
You have not written proper XPath
driver.findElement(By.xpath("(//span[contains(text(), 'Continue Booking')])[1]/following::button[1]")).click();
log.debug("Click Continue ");

Given xpath expression "//div[contains(#class='loader-overlay')]" is invalid with Selenium

After upgrading from version 2.53 to version 3.14 Selenium says
Given xpath expression "//div[contains(#class='loader-overlay')]" is invalid
This code
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver/v0.23.0");
FirefoxOptions options = new FirefoxOptions();
//...
driver = new FirefoxDriver(options);
WebElement loaderElement = driver.findElement(By.xpath("//div[contains(#class='loader-overlay')]"));
produces this error
org.openqa.selenium.InvalidSelectorException: Given xpath expression "//div[contains(#class='loader-overlay')]" is invalid: [Exception... "<no message>" nsresult: "0x8060000d (<unknown>)" location: "JS frame :: chrome://marionette/content/element.js :: element.findByXPath :: line 401" data: no]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'xxx', ip: '10.233.112.79', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-116-generic', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 64.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 2736, moz:profile: /tmp/rust_mozprofile.OP8KKQ..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, platformVersion: 4.4.0-116-generic, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
You need to replace
//div[contains(#class='loader-overlay')]
with
//div[contains(#class, 'loader-overlay')]
Note that you should use [#attr = "value"] syntax if you want to check if attribute value is exactly the "value", but contains syntax is [contains(#attr, "value")]
This error message...
org.openqa.selenium.InvalidSelectorException: Given xpath expression "//div[contains(#class='loader-overlay')]" is invalid: [Exception... "<no message>" nsresult: "0x8060000d (<unknown>)" location: "JS frame :: chrome://marionette/content/element.js :: element.findByXPath :: line 401" data: no]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
...implies that that the xpath expression was not a valid one.
Solution
If the element is having a single class attribute as loader-overlay you need to change the xpath as:
"//div[#class='loader-overlay']"
If the element is having multiple class attributes and loader-overlay is one among them you need to change the xpath as:
"//div[contains(#class, 'loader-overlay')]"