我试图在一个网页上使用以下代码点击几个元素,但它给出了元素不可交互错误。我也应用了等待条件,但没有帮助。
这是我的代码:
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();
错误 :
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
最佳答案
您尝试点击的元素存在于页面上,但不可点击/不可交互,这就是您获得 element not interactable
的原因。异常(exception)。
您需要使用下面提到的 xpath 来选择元素,它会起作用:
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();
关于selenium - 获取以下代码的 "element not interactable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55637344/