diff --git a/tests/CI.py b/tests/CI.py index 19a5de2..6a3c864 100644 --- a/tests/CI.py +++ b/tests/CI.py @@ -1,4 +1,5 @@ import unittest +from time import sleep from selenium import webdriver from selenium.webdriver.chrome.webdriver import WebDriver @@ -21,27 +22,11 @@ def get_browser() -> WebDriver: class TestCase(unittest.TestCase): def test_spider(self): browser = get_browser() - tweet = Tweet('https://twitter.com/_CASTSTATION/status/1697029186777706544', is_ci_test=True) - try: - tweet.load_data(browser) - except: - element = browser.find_element(By.XPATH,"//*[contains(text(), '{}')]".format('miku miku oo ee oo')) - element_xpath = browser.execute_script( - "function getElementXPath(element) {" - " if (element && element.id) {" - " return 'id(\"' + element.id + '\")';" - " } else {" - " return getElementXPath(element.parentNode) + '/' + element.tagName.toLowerCase();" - " }" - "}" - "return getElementXPath(arguments[0]);", - element - ) - - # 输出匹配到的元素的XPath表达式 - print("匹配到的元素的XPath表达式:", element_xpath) - browser.save_screenshot('debug.png') - self.assertEqual(True, True) + browser.get('https://twitter.com/_CASTSTATION/status/1697029186777706544') + sleep(20) + element = browser.find_element(By.XPATH,"//*[contains(text(), '{}')]".format('miku miku oo ee oo')) + browser.save_screenshot('debug.png') + self.assertIn('miku miku oo ee oo',element.get_attribute('innerHTML')) if __name__ == '__main__': diff --git a/twitter_user_tweet_crawler/tweet.py b/twitter_user_tweet_crawler/tweet.py index afc6f36..77de34f 100644 --- a/twitter_user_tweet_crawler/tweet.py +++ b/twitter_user_tweet_crawler/tweet.py @@ -87,7 +87,6 @@ def click_sensitive_element(): result = None available_driver.get(self.link) wait = WebDriverWait(available_driver, 20) - sleep(60) element = wait.until(EC.presence_of_element_located((By.XPATH, '//*/time/ancestor::*[3]'))) time_stamp = element.find_element(By.XPATH, '//time').get_attribute('datetime') location = True