Jump to content
Fórum Script Brasil
  • 0

Selenium webdriver


Ana Bon

Question

Bom dia pessoal, tudo bem ?

 

Estou a dois dias parada em uma linha de código somente, estou tentando da "enter" em um elemento mas ele sempre me retorna o erro 

PS C:\Msg portabilidade> & C:/Users/TINETFLEX_ANABON/anaconda3/python.exe "c:/Msg portabilidade/Enviar WhatsApp Python.py"
Traceback (most recent call last):
  File "c:\Msg portabilidade\Enviar WhatsApp Python.py", line 36, in <module>
    while len(navegador.find_elements(By.ID, 'side')) < 1:
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 772, in find_elements
    return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 348, in execute     
    self.error_handler.check_response(response)
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded
Stacktrace:
PS C:\Msg portabilidade> & C:/Users/TINETFLEX_ANABON/anaconda3/python.exe "c:/Msg portabilidade/Enviar WhatsApp Python.py"
Traceback (most recent call last):
  File "c:\Msg portabilidade\Enviar WhatsApp Python.py", line 40, in <module>
    contato = navegador.find_element(By.XPATH, ('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 742, in find_element    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 348, in execute     
    self.error_handler.check_response(response)
  File "C:\Users\TINETFLEX_ANABON\anaconda3\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id="main"]/footer/div[1]/div[2]/div/div[2]; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:189:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:507:5
dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:132:16

# já estamos com o login feito no whatsapp web
for i, mensagem in enumerate(contatos_df['Mensagem']):
    pessoa = contatos_df.loc[i, "Pessoa"]
    numero = contatos_df.loc[i, "Número"]
    texto = urllib.parse.quote(f"Oi {pessoa}! {mensagem}")
    link = f"https://web.whatsapp.com/send?phone={numero}&text={texto}"
    navegador.get(link)
    while len(navegador.find_elements(By.ID, 'side')) < 1:
        time.sleep(1)
    #navegador.find_element(By.XPATH, '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]').send_keys(Keys.ENTER)
    #element = navegador.find_element(By.xpath, '//*[@id="main"]').send_keys()
    contato = navegador.find_element(By.XPATH, ('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'))
    contato.sendKeys(Keys.ENTER)
   
    time.sleep(10)
       
   
navegador.find_elements(By.ID, 'side')
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.9k
×
×
  • Create New...