質問編集履歴
1
ついか
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,4 +6,78 @@
|
|
6
6
|
|
7
7
|
x_pathを用いてログイン画面の移動やパスワードの入力を自動で行えるプログラミングを組んでいるのですがその際にほかサイトにて調べたとおりにx_pathを調べてコピペしていて期待通りなら動くはずなのですが、うまくいきません。
|
8
8
|
|
9
|
-
下記にてログイン部分のコード、ならびにエラー内容を記しますのでわかる方がいらっしゃいましたらご教ください。
|
9
|
+
下記にてログイン部分のコード、ならびにエラー内容を記しますのでわかる方がいらっしゃいましたらご教授ください。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
コード
|
14
|
+
|
15
|
+
def Login(self):
|
16
|
+
|
17
|
+
url = "https://twitter.com/"
|
18
|
+
|
19
|
+
self.driver.get(url)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
print(self.driver.current_url)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
self.driver.find_element_by_xpath('//*[@id="doc"]/div/div[1]/div[1]/div[2]/div[2]/div/a[2]').click()
|
28
|
+
|
29
|
+
time.sleep(5)
|
30
|
+
|
31
|
+
id = self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input')
|
32
|
+
|
33
|
+
id.send_keys(self.yourId)
|
34
|
+
|
35
|
+
time.sleep(5)
|
36
|
+
|
37
|
+
password = self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input')
|
38
|
+
|
39
|
+
password.send_keys(self.yourPassWord)
|
40
|
+
|
41
|
+
time.sleep(5)
|
42
|
+
|
43
|
+
print(self.driver.current_url)
|
44
|
+
|
45
|
+
self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/div[2]/button').click()
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
エラー
|
50
|
+
|
51
|
+
DevTools listening on ws://127.0.0.1:53968/devtools/browser/23298def-2b97-492d-b4b6-156d59393a66
|
52
|
+
|
53
|
+
https://twitter.com/
|
54
|
+
|
55
|
+
Traceback (most recent call last):
|
56
|
+
|
57
|
+
File "AutoTweet.py", line 153, in <module>
|
58
|
+
|
59
|
+
tweet1.Login()
|
60
|
+
|
61
|
+
File "AutoTweet.py", line 29, in Login
|
62
|
+
|
63
|
+
self.driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/a[2]').click()
|
64
|
+
|
65
|
+
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
|
66
|
+
|
67
|
+
return self.find_element(by=By.XPATH, value=xpath)
|
68
|
+
|
69
|
+
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
|
70
|
+
|
71
|
+
return self.execute(Command.FIND_ELEMENT, {
|
72
|
+
|
73
|
+
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
|
74
|
+
|
75
|
+
self.error_handler.check_response(response)
|
76
|
+
|
77
|
+
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
|
78
|
+
|
79
|
+
raise exception_class(message, screen, stacktrace)
|
80
|
+
|
81
|
+
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/a[2]"}
|
82
|
+
|
83
|
+
(Session info: chrome=80.0.3987.100)
|