我正在制作一个机器人来一次又一次删除并重新创建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