selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:._ 2zCDG

时间:2019-01-13 10:05:52

标签: python-3.x selenium firefox geckodriver

我找不到“无法找到元素:._ 2zCDG”的任何内容 这是怎么了试图使用Selenium Geckodriver编写脚本的脚本,但是无法弄清楚问题出在哪里,谢谢。

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import requests
import pyautogui
import os
import time
import pandas as pd

options = Options()
options.set_headless(headless=True)
browser = webdriver.Firefox()#firefox_options=options)

browser.get('https://web.whatsapp.com')
print('Scan and get started')
time.sleep(10)

bot_users = {}

while True:
    unread = browser.find_elements_by_class_name("OUeyt")
    if len(unread) > 0:
        ele = unread[-1]
        action = webdriver.common.action_chains.ActionChains(browser)
        action.move_to_element_with_offset(ele, 0, -20)
        try:
            action.click()
            action.perform()
            action.click()
            action.perform()
        except:
            pass    
        name = browser.find_element_by_class_name("_2zCDG").text

错误:

Traceback (most recent call last):
      File "bot.py", line 67, in <module>
        name = browser.find_element_by_class_name("_2zCDG").text
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 564, in find_element_by_class_name
        return self.find_element(by=By.CLASS_NAME, value=name)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
        'value': value})['value']
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ._2zCDG

0 个答案:

没有答案