Radulepy / InstagramBot

Instagram AUTO Like and Comment Python BOT
GNU General Public License v2.0
134 stars 48 forks source link

NoSuchElementException #16

Closed CGalactica closed 2 years ago

CGalactica commented 2 years ago

Describe the bug Error is thrown after running the .py file. Browser spawns but unable to locate the fields, likely because IG has made updates since the last commit.

To Reproduce Steps to reproduce the behavior:

  1. Go to directory via cmd (containing the correct chrome driver == chrome browser version)
  2. Run 'Python instagramBot.py'
  3. Browser opens but then nothing happens.
  4. See error message below.

Expected behavior Spawn new browser window, go to Instagram website and login as user with provided hard-coded credentials.

Desktop (please complete the following information):

**Chrome Driver

Additional context

python instagramBot.py
C:\Users\John\OneDrive\Desktop\InstagramBot-master\instagramBot.py:21: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser = webdriver.Chrome(executable_path=r'C:\Users\John\OneDrive\Desktop\InstagramBot-master\chromedriver.exe')  # <----- ENTER PATH HERE

DevTools listening on ws://127.0.0.1:49429/devtools/browser/1e2dcb9c-f950-4f30-8fd9-97bf8917f03a
C:\Users\John\OneDrive\Desktop\InstagramBot-master\instagramBot.py:62: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
  acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[1]');
Traceback (most recent call last):
  File "C:\Users\John\OneDrive\Desktop\InstagramBot-master\instagramBot.py", line 85, in <module>
    start()
  File "C:\Users\John\OneDrive\Desktop\InstagramBot-master\instagramBot.py", line 62, in start
    acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[1]');
  File "C:\Users\John\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 521, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\John\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 1248, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\John\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute
    self.error_handler.check_response(response)
  File "C:\Users\John\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div/div/button[1]"}
  (Session info: chrome=100.0.4896.88)
Stacktrace:
Backtrace:
        Ordinal0 [0x00297413+2389011]
        Ordinal0 [0x00229F61+1941345]
        Ordinal0 [0x0011C658+837208]
        Ordinal0 [0x001491DD+1020381]
        Ordinal0 [0x0014949B+1021083]
        Ordinal0 [0x00176032+1204274]
        Ordinal0 [0x00164194+1130900]
        Ordinal0 [0x00174302+1196802]
        Ordinal0 [0x00163F66+1130342]
        Ordinal0 [0x0013E546+976198]
        Ordinal0 [0x0013F456+980054]
        GetHandleVerifier [0x00449632+1727522]
        GetHandleVerifier [0x004FBA4D+2457661]
        GetHandleVerifier [0x0032EB81+569713]
        GetHandleVerifier [0x0032DD76+566118]
        Ordinal0 [0x00230B2B+1968939]
        Ordinal0 [0x00235988+1989000]
        Ordinal0 [0x00235A75+1989237]
        Ordinal0 [0x0023ECB1+2026673]
        BaseThreadInitThunk [0x76FFFA29+25]
        RtlGetAppContainerNamedObjectPath [0x77C77A7E+286]
        RtlGetAppContainerNamedObjectPath [0x77C77A4E+238]
        (No symbol) [0x00000000]

C:\Users\John\OneDrive\Desktop\InstagramBot-master>[956:4248:0412/111037.859:ERROR:device_event_log_impl.cc(214)] [11:10:37.859] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)`
Radulepy commented 2 years ago

@CGalactica Try changing line 62 from: acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[1]'); to acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[2]');

CGalactica commented 2 years ago

After changing line 62 the browser window spawned but nothing happened at the login screen. Below error was logged to the console. The username and password fields are not being filled in either fyi.

DevTools listening on ws://127.0.0.1:59373/devtools/browser/9eb658fd-052a-43f6-ae43-3473742fd85d C:\Users\Blake\OneDrive\Desktop\InstagramBot-master\instagramBot.py:62: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[2]'); Traceback (most recent call last): File "C:\Users\Blake\OneDrive\Desktop\InstagramBot-master\instagramBot.py", line 85, in start() File "C:\Users\Blake\OneDrive\Desktop\InstagramBot-master\instagramBot.py", line 62, in start acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[2]'); File "C:\Users\Blake\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 521, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\Blake\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 1248, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Users\Blake\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute self.error_handler.check_response(response) File "C:\Users\Blake\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div/div/button[2]"} (Session info: chrome=100.0.4896.88) Stacktrace: Backtrace: Ordinal0 [0x00D67413+2389011] Ordinal0 [0x00CF9F61+1941345] Ordinal0 [0x00BEC658+837208] Ordinal0 [0x00C191DD+1020381] Ordinal0 [0x00C1949B+1021083] Ordinal0 [0x00C46032+1204274] Ordinal0 [0x00C34194+1130900] Ordinal0 [0x00C44302+1196802] Ordinal0 [0x00C33F66+1130342] Ordinal0 [0x00C0E546+976198] Ordinal0 [0x00C0F456+980054] GetHandleVerifier [0x00F19632+1727522] GetHandleVerifier [0x00FCBA4D+2457661] GetHandleVerifier [0x00DFEB81+569713] GetHandleVerifier [0x00DFDD76+566118] Ordinal0 [0x00D00B2B+1968939] Ordinal0 [0x00D05988+1989000] Ordinal0 [0x00D05A75+1989237] Ordinal0 [0x00D0ECB1+2026673] BaseThreadInitThunk [0x76FFFA29+25] RtlGetAppContainerNamedObjectPath [0x77C77A7E+286] RtlGetAppContainerNamedObjectPath [0x77C77A4E+238]

C:\Users\Blake\OneDrive\Desktop\InstagramBot-master>[8172:4264:0412/195538.715:ERROR:device_event_log_impl.cc(214)] [19:55:38.715] Bluetooth: bluetooth_adapter_winrt.cc:1075 Getting Default Adapter failed.

Radulepy commented 2 years ago

@CGalactica perhaps you should add a delay before calling the start() function at the beginning of the script. (line 62) I suspect your browser takes a little to long to load thus not finding all the buttons.

If the script can't find your login inputs, just right click on the input field -> inspect element -> right click on the outlined element -> copy full X Path and paste it where the inputs are (line 66 for username and 68 for pass)

CGalactica commented 2 years ago

Thanks I'll try that. Also, apologies for the belated reply.