質問編集履歴

1

catch節を追加しました

2020/01/03 01:42

投稿

you_19000
you_19000

スコア31

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,85 @@
79
79
  (node:1491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
80
80
 
81
81
  ```
82
+
83
+
84
+
85
+ ---
86
+
87
+ **2020/01/03**
88
+
89
+ 頂いた内容よりコード修正(catch節追加)
90
+
91
+ ```TypeScript
92
+
93
+ import { Builder, WebDriver } from "selenium-webdriver";
94
+
95
+
96
+
97
+ (async () => {
98
+
99
+ /** iosのsafariを指定してWebDriverを起動 */
100
+
101
+ const driver: WebDriver = await new Builder().forBrowser("safari", "604.1", "ios").build();
102
+
103
+
104
+
105
+ try {
106
+
107
+
108
+
109
+ /** ブラウザの操作を開始する */
110
+
111
+ console.log("start");
112
+
113
+ await driver.get("https://google.co.jp");
114
+
115
+ await driver.sleep(3000);
116
+
117
+ /** 終了時処理 */
118
+
119
+ console.log("正常終了。Driverを終了します");
120
+
121
+ await driver.quit();
122
+
123
+
124
+
125
+ } catch (e) {
126
+
127
+ /** Error時処理 */
128
+
129
+ console.log("Errorを検知。Driverを終了します");
130
+
131
+ await driver.quit();
132
+
133
+ }
134
+
135
+ })();
136
+
137
+ ```
138
+
139
+
140
+
141
+ ```Error
142
+
143
+ (node:2227) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Could not create a session: The Safari instance terminated while trying to pair with it.
144
+
145
+ at Object.throwDecodedError (/Users/yuichiro/dev/ios-rpa/node_modules/selenium-webdriver/lib/error.js:550:15)
146
+
147
+ at parseHttpResponse (/Users/yuichiro/dev/ios-rpa/node_modules/selenium-webdriver/lib/http.js:563:13)
148
+
149
+ at Executor.execute (/Users/yuichiro/dev/ios-rpa/node_modules/selenium-webdriver/lib/http.js:489:26)
150
+
151
+ at processTicksAndRejections (internal/process/task_queues.js:93:5)
152
+
153
+ (node:2227) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
154
+
155
+ (node:2227) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
156
+
157
+ yuichiro@you-2 ios-rpa % npx ts-node ./src/main.ts
158
+
159
+ start
160
+
161
+ 正常終了。Driverを終了します
162
+
163
+ ```