Instagram Bot: Click Button in Firefox with Selenium Python











up vote
0
down vote

favorite












I'm making an Instagram Bot (from a YT tutorial) and I can't get past the "Turn On Notifications" pop-up that appears after login.



I want to click "Turn On"



How do I click the button? Here's the xpath and what I see after inspection.



Xpath:



/html/body/div[2]/div/div/div/div[3]/button[1]


Inspection:



<button class="aOOlW  bIiDR  " tabindex="0">Turn On</button>


Here's my code. Can anyone tell me what to add and where? I'm attempting to click the button at the very bottom...



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

def print_same_line(text):
sys.stdout.write('r')
sys.stdout.flush()
sys.stdout.write(text)
sys.stdout.flush()


class InstagramBot:

def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Firefox()

def closeBrowser(self):
self.driver.close()

def login(self):
driver = self.driver
driver.get("https://www.instagram.com/")
time.sleep(2)
login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
login_button.click()
time.sleep(2)
user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
user_name_elem.clear()
user_name_elem.send_keys(self.username)
passworword_elem = driver.find_element_by_xpath("//input[@name='password']")
passworword_elem.clear()
passworword_elem.send_keys(self.password)
passworword_elem.send_keys(Keys.RETURN)
time.sleep(2)
notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
notify_button.click()
time.sleep(2)









share|improve this question







New contributor




BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I'm making an Instagram Bot (from a YT tutorial) and I can't get past the "Turn On Notifications" pop-up that appears after login.



    I want to click "Turn On"



    How do I click the button? Here's the xpath and what I see after inspection.



    Xpath:



    /html/body/div[2]/div/div/div/div[3]/button[1]


    Inspection:



    <button class="aOOlW  bIiDR  " tabindex="0">Turn On</button>


    Here's my code. Can anyone tell me what to add and where? I'm attempting to click the button at the very bottom...



    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time

    def print_same_line(text):
    sys.stdout.write('r')
    sys.stdout.flush()
    sys.stdout.write(text)
    sys.stdout.flush()


    class InstagramBot:

    def __init__(self, username, password):
    self.username = username
    self.password = password
    self.driver = webdriver.Firefox()

    def closeBrowser(self):
    self.driver.close()

    def login(self):
    driver = self.driver
    driver.get("https://www.instagram.com/")
    time.sleep(2)
    login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
    login_button.click()
    time.sleep(2)
    user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
    user_name_elem.clear()
    user_name_elem.send_keys(self.username)
    passworword_elem = driver.find_element_by_xpath("//input[@name='password']")
    passworword_elem.clear()
    passworword_elem.send_keys(self.password)
    passworword_elem.send_keys(Keys.RETURN)
    time.sleep(2)
    notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
    notify_button.click()
    time.sleep(2)









    share|improve this question







    New contributor




    BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm making an Instagram Bot (from a YT tutorial) and I can't get past the "Turn On Notifications" pop-up that appears after login.



      I want to click "Turn On"



      How do I click the button? Here's the xpath and what I see after inspection.



      Xpath:



      /html/body/div[2]/div/div/div/div[3]/button[1]


      Inspection:



      <button class="aOOlW  bIiDR  " tabindex="0">Turn On</button>


      Here's my code. Can anyone tell me what to add and where? I'm attempting to click the button at the very bottom...



      from selenium import webdriver
      from selenium.webdriver.common.keys import Keys
      import time

      def print_same_line(text):
      sys.stdout.write('r')
      sys.stdout.flush()
      sys.stdout.write(text)
      sys.stdout.flush()


      class InstagramBot:

      def __init__(self, username, password):
      self.username = username
      self.password = password
      self.driver = webdriver.Firefox()

      def closeBrowser(self):
      self.driver.close()

      def login(self):
      driver = self.driver
      driver.get("https://www.instagram.com/")
      time.sleep(2)
      login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
      login_button.click()
      time.sleep(2)
      user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
      user_name_elem.clear()
      user_name_elem.send_keys(self.username)
      passworword_elem = driver.find_element_by_xpath("//input[@name='password']")
      passworword_elem.clear()
      passworword_elem.send_keys(self.password)
      passworword_elem.send_keys(Keys.RETURN)
      time.sleep(2)
      notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
      notify_button.click()
      time.sleep(2)









      share|improve this question







      New contributor




      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm making an Instagram Bot (from a YT tutorial) and I can't get past the "Turn On Notifications" pop-up that appears after login.



      I want to click "Turn On"



      How do I click the button? Here's the xpath and what I see after inspection.



      Xpath:



      /html/body/div[2]/div/div/div/div[3]/button[1]


      Inspection:



      <button class="aOOlW  bIiDR  " tabindex="0">Turn On</button>


      Here's my code. Can anyone tell me what to add and where? I'm attempting to click the button at the very bottom...



      from selenium import webdriver
      from selenium.webdriver.common.keys import Keys
      import time

      def print_same_line(text):
      sys.stdout.write('r')
      sys.stdout.flush()
      sys.stdout.write(text)
      sys.stdout.flush()


      class InstagramBot:

      def __init__(self, username, password):
      self.username = username
      self.password = password
      self.driver = webdriver.Firefox()

      def closeBrowser(self):
      self.driver.close()

      def login(self):
      driver = self.driver
      driver.get("https://www.instagram.com/")
      time.sleep(2)
      login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
      login_button.click()
      time.sleep(2)
      user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
      user_name_elem.clear()
      user_name_elem.send_keys(self.username)
      passworword_elem = driver.find_element_by_xpath("//input[@name='password']")
      passworword_elem.clear()
      passworword_elem.send_keys(self.password)
      passworword_elem.send_keys(Keys.RETURN)
      time.sleep(2)
      notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
      notify_button.click()
      time.sleep(2)






      python macos selenium firefox instagram






      share|improve this question







      New contributor




      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 22 hours ago









      BlockyBlock

      1




      1




      New contributor




      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Solution!



          Instead of using this...



          notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
          notify_button.click()
          time.sleep(2)


          Use this!



          notify_element = driver.find_element_by_css_selector("COPY PASTE CSS SELECTOR HERE")
          notify_element.send_keys(Keys.TAB)
          time.sleep(1)
          notify_element.send_keys(Keys.RETURN)
          time.sleep(2)





          share|improve this answer










          New contributor




          BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            BlockyBlock is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237338%2finstagram-bot-click-button-in-firefox-with-selenium-python%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Solution!



            Instead of using this...



            notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
            notify_button.click()
            time.sleep(2)


            Use this!



            notify_element = driver.find_element_by_css_selector("COPY PASTE CSS SELECTOR HERE")
            notify_element.send_keys(Keys.TAB)
            time.sleep(1)
            notify_element.send_keys(Keys.RETURN)
            time.sleep(2)





            share|improve this answer










            New contributor




            BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






















              up vote
              0
              down vote













              Solution!



              Instead of using this...



              notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
              notify_button.click()
              time.sleep(2)


              Use this!



              notify_element = driver.find_element_by_css_selector("COPY PASTE CSS SELECTOR HERE")
              notify_element.send_keys(Keys.TAB)
              time.sleep(1)
              notify_element.send_keys(Keys.RETURN)
              time.sleep(2)





              share|improve this answer










              New contributor




              BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                up vote
                0
                down vote










                up vote
                0
                down vote









                Solution!



                Instead of using this...



                notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
                notify_button.click()
                time.sleep(2)


                Use this!



                notify_element = driver.find_element_by_css_selector("COPY PASTE CSS SELECTOR HERE")
                notify_element.send_keys(Keys.TAB)
                time.sleep(1)
                notify_element.send_keys(Keys.RETURN)
                time.sleep(2)





                share|improve this answer










                New contributor




                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                Solution!



                Instead of using this...



                notify_button = browser.find_element_by_xpath('//button[text()="Turn On"]')
                notify_button.click()
                time.sleep(2)


                Use this!



                notify_element = driver.find_element_by_css_selector("COPY PASTE CSS SELECTOR HERE")
                notify_element.send_keys(Keys.TAB)
                time.sleep(1)
                notify_element.send_keys(Keys.RETURN)
                time.sleep(2)






                share|improve this answer










                New contributor




                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer








                edited 19 hours ago









                William Jones

                6110




                6110






                New contributor




                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 19 hours ago









                BlockyBlock

                1




                1




                New contributor




                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                BlockyBlock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                    BlockyBlock is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    BlockyBlock is a new contributor. Be nice, and check out our Code of Conduct.













                    BlockyBlock is a new contributor. Be nice, and check out our Code of Conduct.












                    BlockyBlock is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237338%2finstagram-bot-click-button-in-firefox-with-selenium-python%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values