Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 找不到类元素Selenium_Python_Selenium_Automation - Fatal编程技术网

Python 找不到类元素Selenium

Python 找不到类元素Selenium,python,selenium,automation,Python,Selenium,Automation,我正在尝试创建一个自动instagram bot,但在尝试选择并单击某个按钮时遇到问题(该按钮是“故事”按钮): html代码部分(与所述按钮相关的代码)如下: 我得到的错误是: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","select

我正在尝试创建一个自动instagram bot,但在尝试选择并单击某个按钮时遇到问题(该按钮是“故事”按钮):

html代码部分(与所述按钮相关的代码)如下:

我得到的错误是:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".tUtVM"}
我试过使用不同的类名,但都不管用


如何解决这个问题?

element=self.driver.find\u element\u by_xpath('//div[contains(@aria label,“Open Stories”)]/following::div')
元素。单击()。您可以按照下面的方法来解决它

    self.driver.get('{}/{}'.format(self.base_url, 'fatcatharvey'))
    WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(By.XPATH, '//div[@role="presentation"]'))
    elements = self.driver.find_elements_by_class_name('tUtVM')
    for i in range(len(elements)):
        elementsTemp = self.driver.find_elements_by_class_name('tUtVM')
        elementsTemp.__getitem__(i).click()
        #Compete the task with opened url
        self.driver.back()

请参阅-特别是“
不要使用代码图像”
,我建议使用XPath。@YunchongJC。请读一读为什么会这样。考虑用格式化的基于文本的相关HTML更新更新问题,代码测试和错误堆栈跟踪。@ ReaveDaviS抱歉,我是新来的,我会检查并相应改变。@ Andrej,我尝试过使用xpath,但仍然不起作用。我尝试过使用xpath,但仍然找不到元素。您的代码可能在
element=self.driver处失败。通过\u class\u name(“cmbtv”)
查找\u element\u?奇怪的是,它大部分时间都能工作!但由于未知的原因,这一部分曾经失败过。
element = self.driver.find_element_by_class_name('tUtVM')
element.click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".tUtVM"}
    self.driver.get('{}/{}'.format(self.base_url, 'fatcatharvey'))
    WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(By.XPATH, '//div[@role="presentation"]'))
    elements = self.driver.find_elements_by_class_name('tUtVM')
    for i in range(len(elements)):
        elementsTemp = self.driver.find_elements_by_class_name('tUtVM')
        elementsTemp.__getitem__(i).click()
        #Compete the task with opened url
        self.driver.back()