Pythonのbotを制作しています。
その際のログイン画面のところでエラーが出てきているのでわかる方に教えていただきたいです。
x_pathを用いてログイン画面の移動やパスワードの入力を自動で行えるプログラミングを組んでいるのですがその際にほかサイトにて調べたとおりにx_pathを調べてコピペしていて期待通りなら動くはずなのですが、うまくいきません。
下記にてログイン部分のコード、ならびにエラー内容を記しますのでわかる方がいらっしゃいましたらご教授ください。
コード
def Login(self):
url = "https://twitter.com/"
self.driver.get(url)
print(self.driver.current_url) self.driver.find_element_by_xpath('//*[@id="doc"]/div/div[1]/div[1]/div[2]/div[2]/div/a[2]').click() time.sleep(5) id = self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input') id.send_keys(self.yourId) time.sleep(5) password = self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input') password.send_keys(self.yourPassWord) time.sleep(5) print(self.driver.current_url) self.driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/div[2]/button').click()
エラー
DevTools listening on ws://127.0.0.1:53968/devtools/browser/23298def-2b97-492d-b4b6-156d59393a66
https://twitter.com/
Traceback (most recent call last):
File "AutoTweet.py", line 153, in <module>
tweet1.Login()
File "AutoTweet.py", line 29, in Login
self.driver.find_element_by_xpath('//[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/a[2]').click()
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
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]"}
(Session info: chrome=80.0.3987.100)
回答1件
あなたの回答
tips
プレビュー