回答編集履歴

1

追記

2020/07/22 13:16

投稿

shirai
shirai

スコア1289

test CHANGED
@@ -13,3 +13,71 @@
13
13
 
14
14
 
15
15
  を入れてみてください。
16
+
17
+
18
+
19
+ # コメントを受けて追記
20
+
21
+
22
+
23
+ だったら[これ](https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit)試してみてください。
24
+
25
+
26
+
27
+ マウスのホバーとその後のクリックの代わりにこれをやるイメージです。
28
+
29
+
30
+
31
+ ```python
32
+
33
+ driver.execute_script('''
34
+
35
+ function post(path, params, method='post') {
36
+
37
+ const form = document.createElement('form');
38
+
39
+ form.method = method;
40
+
41
+ form.action = path;
42
+
43
+
44
+
45
+ for (const key in params) {
46
+
47
+ if (params.hasOwnProperty(key)) {
48
+
49
+ const hiddenField = document.createElement('input');
50
+
51
+ hiddenField.type = 'hidden';
52
+
53
+ hiddenField.name = key;
54
+
55
+ hiddenField.value = params[key];
56
+
57
+
58
+
59
+ form.appendChild(hiddenField);
60
+
61
+ }
62
+
63
+ }
64
+
65
+
66
+
67
+ document.body.appendChild(form);
68
+
69
+ form.submit();
70
+
71
+ }
72
+
73
+ post('/contact/', {name: 'Johnny Bravo'});
74
+
75
+ ''')
76
+
77
+ ```
78
+
79
+
80
+
81
+ DOM上に無理やりこのJSを出現させて実行するイメージです。
82
+
83
+ 実際のところはGETリクエストになると思います。