0
votes

I am getting below exception when I am trying to do driver.findElements(By.xpath("//button/span[text()='Cancel']/../following-sibling::button/span[text()='Ok']")).size()!=0.

Though I am using driver.findElements at other places also, but its failing here.

Chrome: 58x version
ChromeDriver: 2.29 version
Selenium: 2.52 version

Error trace-back:

org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot find context with specified id"} (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 5.44 seconds Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16' System info: host: 'Iaglab2', ip: '', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_75' *** Element info: {Using=xpath, value=//button/span[text()='Cancel']/../following-sibling::button/span[text()='Ok']} Session ID: 44c20fabdca96942ee2f9de6fc7d3c23 Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=WIN8_1, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\hravi\AppData\Local\Temp\scoped_dir9172_8986, chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=58.0.3029.110, pageLoadStrategy=normal, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]

2
Can you check whether element is inside frame or not ?Abhinav
Yes, Element is inside frame but I am already on that frame and performing other actions before its getting failed here. And same code is working on other machine with same configurationAvats
i'm getting the same exact issue, not consistently though.kevin

2 Answers

1
votes

Looks like it is a bug with Chrome driver.

Chrome driver bug -1224

But this bug was fixed for chrome driver v2.21. But we are again facing similar issue. I am facing same issue with 2.30 and even with latest 2.32 versions.

0
votes

Alternatively, you could "ignore" this exception, so instead of except NoSuchElementException:, you could generalize all exceptions

def check_exists_by_xpath(xpath,driver):
try:
    driver.find_element_by_xpath(xpath)
except: #All exceptions are handeled here
    return False
return True

It worked for me