问题:python,调用自动化过程中新打开了一个窗口,不知道哪一步写错了
解决方法:
1.简化所有步骤如下,检查是否流程没问题:
class TestNotes1:
def test_note(self):
url = "https://www.zoho.com.cn/notebook/"
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(3)
driver.get(url)
# 点击登录按钮
driver.find_element_by_xpath('//*[@id="head"]/div[1]/a[2]').click()
# 输入登录账号
driver.find_element_by_id('login_id').send_keys("765120214@qq.com")
# 点击下一步
driver.find_element_by_id('nextbtn').click()
# 输入密码
driver.find_element_by_id('password').send_keys('xmm765120214')
# 点击登录按钮
driver.find_element_by_id('nextbtn').click()
# 点击写笔记按钮
driver.find_element_by_xpath('//*[@class="col-auto bg-black-strict"]//div[@class="row no-gutters"]/div[2]').click()
# 填写标题
driver.find_element_by_id('title-editor').send_keys("测试1")
# 切换iframe
iframe_ele = driver.find_element_by_xpath('//*[@class="iframeWrapper"]/iframe')
driver.switch_to.frame(iframe_ele)
sleep(1)
# 填写内容
driver.find_element_by_xpath('//html/body/div').send_keys("内容1")
# 切回主文档
driver.switch_to.default_content()
sleep(1)
# 点击发布按钮
driver.find_element_by_xpath(
'//*[@id="note-modal"]//text-note-editor/div/div[1]/div[2]').click()
# 获取toast
# toast = driver.find_element_by_id('toast-message-text').is_displayed()
toast = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.ID, 'toast-message-text')))
status = toast.is_displayed()
assert status == True
driver.quit()
2.确认1没问题,检查url传入是否正确
3.检查driver传入是否正确
from page.basepage import BasePage
from page.notes.notes import Notes
class Index(BasePage):
def wait_sleep(self,sleeps):
self.sleep(sleeps)
return self
def notes(self):
'''点击笔记本'''
return Notes(self._driver) #如果跳转页面,这里没有传入self._driver就会重新打开窗口