createChapterLogic.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import time
  2. from selenium.common import TimeoutException
  3. from base.WebKeys import WebKeys
  4. class CreateChapterPage(WebKeys):
  5. def create_Chapter(self):
  6. # 显性等待作者专区元素并进行点击
  7. locator = ("link text", "作家专区")
  8. self.locator_with_wait(*locator).click()
  9. #切换windows窗口
  10. self.change_window(-1)
  11. # 点击章节管理
  12. locator = ("partial link text", "章节管理")
  13. self.locator_with_wait(*locator).click()
  14. # 切换窗口句柄
  15. self.change_window(-1)
  16. try:
  17. # 如果有数据,点击某个元素
  18. locator = ("xpath", "//*[@id='hasContentDiv']/div[1]/div/a")
  19. self.locator_with_wait(*locator).click()
  20. except TimeoutException:
  21. # 如果没有数据,点击另一个元素
  22. locator = ("xpath", "//*[@id='noContentDiv']/div/a")
  23. self.locator_with_wait(*locator).click()
  24. except Exception:
  25. print("章节管理元素未找到")
  26. # 显性等待章节名元素出现并进行输入从操作
  27. locator = ("id", "bookIndex")
  28. bookname=self.locator_with_wait(*locator).send_keys(f"章节名-{str(int(time.time()))}")
  29. # 显性等待章节内容元素出现并进行输入从操作
  30. locator = ("id", "bookContent")
  31. self.locator_with_wait(*locator).send_keys(f"章节内容-{str(int(time.time()))}")
  32. # 显性等待收费元素出现并点击
  33. locator = ("css selector", '[name="isVip"][value="1"]')
  34. self.locator_with_wait(*locator).click()
  35. # 显性等待提交元素出现并进行点击
  36. locator = ("id", "btnRegister")
  37. self.locator_with_wait(*locator).click()
  38. return bookname