硒陈旧元素Python

时间:2020-09-24 20:48:52

标签: python-3.x selenium

我正在制作一个机器人来一次又一次删除并重新创建Discord频道。

即使刷新后再次收集元素,代码也会显示过时的元素错误

def remake_channels(self):
        sleep(5)
        script = """
            document.querySelectorAll('a[aria-label="aa"')[0].click()
        """
        self.driver.execute_script(script)
        def delete_channel():
            channels = self.driver.find_elements_by_xpath("//div[contains(@class, 'content-3at_AU')]")
            for channel in channels:
                text = channel.get_attribute('innerText')
                if text == 'new':
                    self.action.context_click(on_element = channel)
                    self.action.perform()
                    self.driver.find_element_by_xpath("//div[contains(text(), 'Delete Channel')]").click()
                    sleep(1)
                    self.driver.find_element_by_xpath("//div[contains(text(), 'Delete Channel')]").click()
                    print("Deleted The Channel")

        def make_channel():
            script = """
            document.querySelectorAll('div[class="contents-18-Yxp"]')[1].click()
            """
            self.driver.execute_script(script)
            sleep(1)
            self.driver.find_element_by_xpath("//input[contains(@class, 'inputDefault-_djjkz input-cIJ7To')]").send_keys('new')
            self.driver.find_element_by_xpath("//div[contains(text(), 'Create Channel')]").click()
            print("Added The Channel!")
                
        delete_channel()
        make_channel()

感谢我的帮助<3

0 个答案:

没有答案