Selenium cannot find form element in google calendar (Python)












1















I am attempting to import calendar events to google calendar through a csv file using Selenium and Python. I am unable to select the form element to input my file path into google. I have tried finding the element by xpath, cssselector and class name and I get the same error every time:




selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element




fileElem = browser.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form')


The example xpath shown above was copied directly through google chrome. Any ideas why I can't get this to work? Thanks! Here's the picture of the element and the HTML code.



screenshot










share|improve this question





























    1















    I am attempting to import calendar events to google calendar through a csv file using Selenium and Python. I am unable to select the form element to input my file path into google. I have tried finding the element by xpath, cssselector and class name and I get the same error every time:




    selenium.common.exceptions.NoSuchElementException: Message: no such
    element: Unable to locate element




    fileElem = browser.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form')


    The example xpath shown above was copied directly through google chrome. Any ideas why I can't get this to work? Thanks! Here's the picture of the element and the HTML code.



    screenshot










    share|improve this question



























      1












      1








      1








      I am attempting to import calendar events to google calendar through a csv file using Selenium and Python. I am unable to select the form element to input my file path into google. I have tried finding the element by xpath, cssselector and class name and I get the same error every time:




      selenium.common.exceptions.NoSuchElementException: Message: no such
      element: Unable to locate element




      fileElem = browser.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form')


      The example xpath shown above was copied directly through google chrome. Any ideas why I can't get this to work? Thanks! Here's the picture of the element and the HTML code.



      screenshot










      share|improve this question
















      I am attempting to import calendar events to google calendar through a csv file using Selenium and Python. I am unable to select the form element to input my file path into google. I have tried finding the element by xpath, cssselector and class name and I get the same error every time:




      selenium.common.exceptions.NoSuchElementException: Message: no such
      element: Unable to locate element




      fileElem = browser.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form')


      The example xpath shown above was copied directly through google chrome. Any ideas why I can't get this to work? Thanks! Here's the picture of the element and the HTML code.



      screenshot







      python selenium gcal






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 2:25









      Mihai Chelaru

      2,377101323




      2,377101323










      asked Nov 16 '18 at 1:38









      Luke O'MalleyLuke O'Malley

      82




      82
























          2 Answers
          2






          active

          oldest

          votes


















          0














          change the xpath with //form[@jsname="GBqgNb"]//input but if still unable to locate, try add WebDriverWait()



          # wait 5 second
          fileElem = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH , '//form[@jsname="GBqgNb"]//input')))
          fileElem.send_keys("/path/to/file")





          share|improve this answer
























          • Thanks a lot! Using WebDriverWait solved my problem!

            – Luke O'Malley
            Nov 16 '18 at 19:00



















          0














          Ok, so I tried it myself and found out that when you open that specific URL, it redirects you to the google sign in page, which doesn't have an element with your XPath. So what you could do is just go to the sign in page and find the forms for username and password, then use sendkeys() to type in your username/password. Then it should redirect you to the right page and the XPath will work.



          Use this code:



          from selenium import webdriver
          import time

          d = webdriver.Chrome("executable file path")

          d.get("https://calendar.google.com/calendar/r/settings/export")
          d.find_element_by_xpath('//*[@id="identifierId"]').send_keys("your email")
          d.find_element_by_xpath('//*[@id="identifierNext"]').click() # Next button
          time.sleep(0.5) # Sometimes the time it takes to load the next page will cause the next line to fail
          d.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("your password")
          d.find_element_by_xpath('//*[@id="passwordNext"]').click() # Next button
          d.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form/label') #Now you have the proper element





          share|improve this answer


























          • Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

            – Luke O'Malley
            Nov 16 '18 at 19:01











          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',
          autoActivateHeartbeat: false,
          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330261%2fselenium-cannot-find-form-element-in-google-calendar-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          change the xpath with //form[@jsname="GBqgNb"]//input but if still unable to locate, try add WebDriverWait()



          # wait 5 second
          fileElem = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH , '//form[@jsname="GBqgNb"]//input')))
          fileElem.send_keys("/path/to/file")





          share|improve this answer
























          • Thanks a lot! Using WebDriverWait solved my problem!

            – Luke O'Malley
            Nov 16 '18 at 19:00
















          0














          change the xpath with //form[@jsname="GBqgNb"]//input but if still unable to locate, try add WebDriverWait()



          # wait 5 second
          fileElem = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH , '//form[@jsname="GBqgNb"]//input')))
          fileElem.send_keys("/path/to/file")





          share|improve this answer
























          • Thanks a lot! Using WebDriverWait solved my problem!

            – Luke O'Malley
            Nov 16 '18 at 19:00














          0












          0








          0







          change the xpath with //form[@jsname="GBqgNb"]//input but if still unable to locate, try add WebDriverWait()



          # wait 5 second
          fileElem = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH , '//form[@jsname="GBqgNb"]//input')))
          fileElem.send_keys("/path/to/file")





          share|improve this answer













          change the xpath with //form[@jsname="GBqgNb"]//input but if still unable to locate, try add WebDriverWait()



          # wait 5 second
          fileElem = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH , '//form[@jsname="GBqgNb"]//input')))
          fileElem.send_keys("/path/to/file")






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 3:35









          ewwinkewwink

          12.2k22440




          12.2k22440













          • Thanks a lot! Using WebDriverWait solved my problem!

            – Luke O'Malley
            Nov 16 '18 at 19:00



















          • Thanks a lot! Using WebDriverWait solved my problem!

            – Luke O'Malley
            Nov 16 '18 at 19:00

















          Thanks a lot! Using WebDriverWait solved my problem!

          – Luke O'Malley
          Nov 16 '18 at 19:00





          Thanks a lot! Using WebDriverWait solved my problem!

          – Luke O'Malley
          Nov 16 '18 at 19:00













          0














          Ok, so I tried it myself and found out that when you open that specific URL, it redirects you to the google sign in page, which doesn't have an element with your XPath. So what you could do is just go to the sign in page and find the forms for username and password, then use sendkeys() to type in your username/password. Then it should redirect you to the right page and the XPath will work.



          Use this code:



          from selenium import webdriver
          import time

          d = webdriver.Chrome("executable file path")

          d.get("https://calendar.google.com/calendar/r/settings/export")
          d.find_element_by_xpath('//*[@id="identifierId"]').send_keys("your email")
          d.find_element_by_xpath('//*[@id="identifierNext"]').click() # Next button
          time.sleep(0.5) # Sometimes the time it takes to load the next page will cause the next line to fail
          d.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("your password")
          d.find_element_by_xpath('//*[@id="passwordNext"]').click() # Next button
          d.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form/label') #Now you have the proper element





          share|improve this answer


























          • Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

            – Luke O'Malley
            Nov 16 '18 at 19:01
















          0














          Ok, so I tried it myself and found out that when you open that specific URL, it redirects you to the google sign in page, which doesn't have an element with your XPath. So what you could do is just go to the sign in page and find the forms for username and password, then use sendkeys() to type in your username/password. Then it should redirect you to the right page and the XPath will work.



          Use this code:



          from selenium import webdriver
          import time

          d = webdriver.Chrome("executable file path")

          d.get("https://calendar.google.com/calendar/r/settings/export")
          d.find_element_by_xpath('//*[@id="identifierId"]').send_keys("your email")
          d.find_element_by_xpath('//*[@id="identifierNext"]').click() # Next button
          time.sleep(0.5) # Sometimes the time it takes to load the next page will cause the next line to fail
          d.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("your password")
          d.find_element_by_xpath('//*[@id="passwordNext"]').click() # Next button
          d.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form/label') #Now you have the proper element





          share|improve this answer


























          • Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

            – Luke O'Malley
            Nov 16 '18 at 19:01














          0












          0








          0







          Ok, so I tried it myself and found out that when you open that specific URL, it redirects you to the google sign in page, which doesn't have an element with your XPath. So what you could do is just go to the sign in page and find the forms for username and password, then use sendkeys() to type in your username/password. Then it should redirect you to the right page and the XPath will work.



          Use this code:



          from selenium import webdriver
          import time

          d = webdriver.Chrome("executable file path")

          d.get("https://calendar.google.com/calendar/r/settings/export")
          d.find_element_by_xpath('//*[@id="identifierId"]').send_keys("your email")
          d.find_element_by_xpath('//*[@id="identifierNext"]').click() # Next button
          time.sleep(0.5) # Sometimes the time it takes to load the next page will cause the next line to fail
          d.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("your password")
          d.find_element_by_xpath('//*[@id="passwordNext"]').click() # Next button
          d.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form/label') #Now you have the proper element





          share|improve this answer















          Ok, so I tried it myself and found out that when you open that specific URL, it redirects you to the google sign in page, which doesn't have an element with your XPath. So what you could do is just go to the sign in page and find the forms for username and password, then use sendkeys() to type in your username/password. Then it should redirect you to the right page and the XPath will work.



          Use this code:



          from selenium import webdriver
          import time

          d = webdriver.Chrome("executable file path")

          d.get("https://calendar.google.com/calendar/r/settings/export")
          d.find_element_by_xpath('//*[@id="identifierId"]').send_keys("your email")
          d.find_element_by_xpath('//*[@id="identifierNext"]').click() # Next button
          time.sleep(0.5) # Sometimes the time it takes to load the next page will cause the next line to fail
          d.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys("your password")
          d.find_element_by_xpath('//*[@id="passwordNext"]').click() # Next button
          d.find_element_by_xpath('//*[@id="YPCqFe"]/div/div/div/div[1]/div[1]/div/form/label') #Now you have the proper element






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 3:23

























          answered Nov 16 '18 at 3:12









          user8969265user8969265

          13




          13













          • Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

            – Luke O'Malley
            Nov 16 '18 at 19:01



















          • Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

            – Luke O'Malley
            Nov 16 '18 at 19:01

















          Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

          – Luke O'Malley
          Nov 16 '18 at 19:01





          Thanks a lot for your help! However, I was still unable to locate the element using the xpath. Did that work for you when you tried it?

          – Luke O'Malley
          Nov 16 '18 at 19:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330261%2fselenium-cannot-find-form-element-in-google-calendar-python%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma