Tôi đang tạo ra một bot với Selenium Python. Tôi đang cố gắng nhấp vào một phần tử không hiển thị [chỉ hiển thị sau khi nhấp vào nút để mở rộng cây], vì vậy tôi đang sử dụng JavaScript để thực thi tập lệnh như thế này:
entity_ID = '1200'
js = """document.querySelector["div[data-id='{0}']"].click[]""".format[entity_ID]
driver.execute_script[js]
Điều này trả về JavascriptException: Message: javascript error: Cannot read property 'click' of null
. Nếu tôi mở rộng cây để phần tử có thể nhìn thấy, mã trên sẽ chạy thành công. Nếu tôi sụp đổ cây để phần tử không còn hiển thị nữa ... mã trên sẽ chạy thành công. Tại sao điều này chỉ hoạt động khi phần tử có thể nhìn thấy hoặc đã được nhìn thấy trong quá khứ?
Phần tử [trong cây] trông như thế này:
Traceback đầy đủ trông như thế này:
JavascriptException Traceback [most recent call last]
in
----> 1 driver.execute_script[js]
~\AppData\Local\conda\conda\envs\robotics\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute_script[self, script, *args]
634 return self.execute[command, {
635 'script': script,
--> 636 'args': converted_args}]['value']
637
638 def execute_async_script[self, script, *args]:
~\AppData\Local\conda\conda\envs\robotics\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute[self, driver_command, params]
319 response = self.command_executor.execute[driver_command, params]
320 if response:
--> 321 self.error_handler.check_response[response]
322 response['value'] = self._unwrap_value[
323 response.get['value', None]]
~\AppData\Local\conda\conda\envs\robotics\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response[self, response]
240 alert_text = value['alert'].get['text']
241 raise exception_class[message, screen, stacktrace, alert_text]
--> 242 raise exception_class[message, screen, stacktrace]
243
244 def _value_or_default[self, obj, key, default]:
JavascriptException: Message: javascript error: Cannot read property 'click' of null
[Session info: chrome=78.0.3904.97]
Mô tả: Mã này hoạt động với selen.webdriver.Chromedriver phiên bản 76
This code works with Selenium.WebDriver.ChromeDriver Version 76
Điều kiện tiên quyết: Google Chrome được cập nhật phiên bản 77.0.3865.90 [bản dựng chính thức] [64 bit] Selenium.WebDriver.Chromedriver Phiên bản 77.0.3865.4000 Windows 10 Windows 10 Windows 10 Windows 10 Windows 10 Windows 10 Windows 10
Google Chrome is up to date Version 77.0.3865.90 [Official Build] [64-bit]
Selenium.WebDriver.ChromeDriver Version 77.0.3865.4000
Windows 10
Kiểm tra: Tôi đang cố gắng đăng nhập bằng mã này
I am trying to login using this code
var myurl = " // loginpage"; trình điều khiển.navigate []. gotourl [myurl]; Chuỗi javaScript = "document.getEuityById ['LoginFormSubmit']. Nhấp [];"; javascriptexecutor.executescript [JavaScript];
driver.Navigate[].GoToUrl[myUrl];
string javaScript = "document.getElementById['loginFormSubmit'].click[];";
javaScriptExecutor.ExecuteScript[javaScript];
Thực tế
Message:
OpenQA.Selenium.WebDriverException : javascript error: Cannot read property 'click' of null
[Session info: chrome=77.0.3865.90]
Chào John,
Tôi đang sử dụng serenity "2.3.10", tôi đang cố gắng mở URL bằng phương pháp openUrl[url]
, tôi đang nhận được dưới ngoại lệ
org.openqa.selenium.JavascriptException: javascript error: Cannot read properties of null [reading 'contains']
Dưới đây là Stacktarce đầy đủ.
org.openqa.selenium.JavascriptException: javascript error: Cannot read properties of null [reading 'contains'] [Session info: chrome=96.0.4664.45] Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'LHTU05CG034579V', ip: '10.21.204.169', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 96.0.4664.45, chrome: {chromedriverVersion: 96.0.4664.45 [76e4c1bb2ab46..., userDataDir: C:\Users\sbhardw9\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:58024}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy[], setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true} Session ID: c7926af25cd9164e62426491f6bfaafd 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.http.W3CHttpResponseCodec.createException[W3CHttpResponseCodec.java:187] at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode[W3CHttpResponseCodec.java:122] at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode[W3CHttpResponseCodec.java:49] 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.RemoteWebDriver.executeScript[RemoteWebDriver.java:489] at net.thucydides.core.webdriver.javascript.JavascriptExecutorFacade.executeScript[JavascriptExecutorFacade.java:64] at net.thucydides.core.pages.jquery.JQueryEnabledPage.executeScriptFrom[JQueryEnabledPage.java:68] at net.thucydides.core.pages.jquery.JQueryEnabledPage.injectJQuery[JQueryEnabledPage.java:60] at net.thucydides.core.pages.jquery.JQueryEnabledPage.activateJQuery[JQueryEnabledPage.java:96] at net.serenitybdd.core.pages.PageObject.addJQuerySupport[PageObject.java:1214] at net.serenitybdd.core.pages.PageObject.openPageAtUrl[PageObject.java:915] at net.serenitybdd.core.pages.PageObject.openUrl[PageObject.java:862]
Chủ Đề