Python Selenium:未正确验证Block-Title.(Magento云) [英] Python Selenium: Block-Title is not properly verified. (Magento Cloud)
问题描述
详细信息:
当前,我正在基于Python-Selenium的Magento Cloud测试用例的项目中编写代码.到目前为止,一切都很好.目前,我只有一个问题,我无法再解释了.
Currently I am writing within a project based on Magento Cloud test cases with Python-Selenium. So far everything is fine. Currently I only have one problem, which I can't explain anymore.
实际上,这仅与验证文本有关.或在个人资料页面中验证区块标题.
Actually it's only about the verification of a text. Or the verification of a block title within a profile page.
我想多次保护,因此定义了2个不同的测试用例.
I would like to secure multiple times, and thus define 2 different test cases.
问题
我总是收到以下消息.
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=78.0.3904.108)
来源
#Verify My Account
driver.get("https:my-url.de")
try: self.assertEqual("Account Information", driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='My Account'])[4]/following::strong[1]").text)
except AssertionError as e: self.verificationErrors.append(str(e))
self.assertEqual("Account Information", driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='My Account'])[4]/following::strong[1]").text)
问题:
- 我使用正确的查询吗?显然不是吗?
- 是Magento的缘故吗?
-
如何检查这些块?
- Do I use the correct query? Apparently no?
- Is it due to Magento
How can I check these blocks?
推荐答案
文本格式的相关HTML将有助于构建规范的答案.但是,你很亲近.要在配置文件页面中声明块标题,您需要为 visibility_of_element_located()
引入 WebDriverWait ,并且可以使用以下
The relevant HTML in text format would have helped to construct a canonical answer. However, you were close. To assert the block title within the profile page you have to you need to induce WebDriverWait for the visibility_of_element_located()
and you can use the following Locator Strategies:
-
使用
CSS_SELECTOR
和text
属性:
#Verify My Account
driver.get("https:my-url.de")
try: self.assertEqual("Account Information", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "main.page-main#maincontent div.block-dashboard-info > div.block-title strong"))).text)
except (TimeoutException, AssertionError) as e: self.verificationErrors.append(str(e))
使用 XPATH
和 get_attribute("innerHTML")
:
#Verify My Account
driver.get("https:my-url.de")
try: self.assertEqual("Account Information", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//main[@class='page-main' and @id='maincontent']//div[@class='block-dashboard-info']/div[@class='block-title']//strong"))).get_attribute("innerHTML"))
except (TimeoutException, AssertionError) as e: self.verificationErrors.append(str(e))
注意:您必须添加以下导入:
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
这篇关于Python Selenium:未正确验证Block-Title.(Magento云)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!