質問編集履歴

2

コードをコードの挿入に書き直しました コードにある try except: break を消去しました

2020/05/25 00:43

投稿

MakiAram
MakiAram

スコア12

test CHANGED
File without changes
test CHANGED
@@ -51,10 +51,6 @@
51
51
  SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id="sentenceText"]/div/span<img class="ranking-number" src="https://www.mittsu-kosen.com/wp-content/themes/jin/img/rank02.png" />' is not a valid XPath expression.
52
52
 
53
53
  (Session info: chrome=83.0.4103.61)
54
-
55
-
56
-
57
- ![イメージ説明](2574049d008df7104bbca53c13ff6a6c.png)のコード
58
54
 
59
55
 
60
56
 

1

コードをコードの挿入に書き直しました コードにある try except: break を消去しました

2020/05/25 00:43

投稿

MakiAram
MakiAram

スコア12

test CHANGED
File without changes
test CHANGED
@@ -18,27 +18,77 @@
18
18
 
19
19
  エラーメッセージ
20
20
 
21
- DevTools listening on ws://127.0.0.1:59484/devtools/browser/8ad5475a-7988-47d8-a6a2-eb5a093fdaf6
21
+ DevTools listening on ws://127.0.0.1:64810/devtools/browser/3a248757-5587-4fec-87d0-18824a118c26
22
22
 
23
23
  etyping.py:17: DeprecationWarning: use driver.switch_to.frame instead
24
24
 
25
25
  driver.switch_to_frame('typing_content')
26
26
 
27
+ Traceback (most recent call last):
28
+
29
+ File "etyping.py", line 30, in <module>
30
+
31
+ sentence = driver.find_element_by_xpath('//*[@id="sentenceText"]/div/span<img class="ranking-number" src="https://www.mittsu-kosen.com/wp-content/themes/jin/img/rank02.png" />').text
32
+
33
+ File "C:\Users\Aram_maki\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
34
+
35
+ return self.find_element(by=By.XPATH, value=xpath)
36
+
37
+ File "C:\Users\Aram_maki\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
38
+
39
+ return self.execute(Command.FIND_ELEMENT, {
40
+
41
+ File "C:\Users\Aram_maki\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
42
+
43
+ self.error_handler.check_response(response)
44
+
45
+ File "C:\Users\Aram_maki\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
46
+
47
+ raise exception_class(message, screen, stacktrace)
48
+
49
+ selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*[@id="sentenceText"]/div/span<img class="ranking-number" src="https://www.mittsu-kosen.com/wp-content/themes/jin/img/rank02.png" /> because of the following error:
50
+
51
+ SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id="sentenceText"]/div/span<img class="ranking-number" src="https://www.mittsu-kosen.com/wp-content/themes/jin/img/rank02.png" />' is not a valid XPath expression.
52
+
53
+ (Session info: chrome=83.0.4103.61)
27
54
 
28
55
 
56
+
29
- ### 該当ソースコード
57
+ ![イメージ説明](2574049d008df7104bbca53c13ff6a6c.png)のコード
30
58
 
31
59
 
32
60
 
33
61
 
34
62
 
35
- ソースコード
63
+ ```ここに言語を入力
64
+
65
+ #e-typingの画面にフォーカス
66
+
67
+ driver.switch_to_frame('typing_content')
68
+
69
+ start_button = driver.find_element_by_xpath('//*[@id="start_btn"]')
70
+
71
+ start_button.click()
72
+
73
+ time.sleep(2)
36
74
 
37
75
 
38
76
 
77
+ #スペースキーを入力
78
+
79
+ body_element = driver.find_element_by_tag_name('body')
80
+
81
+ body_element.send_keys(Keys.SPACE)
82
+
83
+ time.sleep(3.5)
84
+
85
+
86
+
87
+ #繰り返す
88
+
39
89
  while True:
40
90
 
41
- try:
91
+ #テキストを取得
42
92
 
43
93
  sentence = driver.find_element_by_xpath('//*[@id="sentenceText"]/div/span<img class="ranking-number" src="https://www.mittsu-kosen.com/wp-content/themes/jin/img/rank02.png" />').text
44
94
 
@@ -50,17 +100,19 @@
50
100
 
51
101
 
52
102
 
53
-
54
-
55
- except:
56
-
57
- break
103
+ ```
58
104
 
59
105
 
106
+
107
+ ![![イメージ説明](bafdb10e4c44b1038aff2854105fc40d.png)](45cff4a8ecfb0f4102df08b13a3b772b.png)
60
108
 
61
109
  ### 試したこと
62
110
 
63
111
  フレームの切り替え
112
+
113
+ try
114
+
115
+ except: break の消去
64
116
 
65
117
 
66
118