python - xPath 不进入下一页

标签 python testing firefox selenium-webdriver xpath

当我使用下面的代码时,网站不会转到下一页。

import unittest
from selenium import webdriver
import time

class ProductPurchase(unittest.TestCase):
    """
    Purchase the product on the website http://automationpractice.com/index.php
    """
    # Preconditions
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://automationpractice.com/index.php")
        self.driver.maximize_window()
    def teardown(self):
        self.driver.quit()
    # Buying a product on the website 
    def test_wrong_agreement(self):
        driver = self.webdriver
        time.sleep(2)
    #Click on "Quick view"
        quickview_btn = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[2]/div/div[1]/ul[1]/li[1]/div/div[1]/div/a[2]").click()


if __name__ == '__main__':
    unittest.main(verbosity=2)

它应该继续到下一页,但 xPath 不起作用。

最佳答案

你好,祝你学习测试自动化好运。

当 xpath 不起作用时,我做的第一件事就是检查它,通常使用像 this 这样的扩展名。一个以确保它是正确的。此外,最好使用较短的 xpath,以便减少出错的空间,即 "//img[@title='Printed Dress']"

关于python - xPath 不进入下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56255437/

相关文章:

ios - StoreKit验证错误 21002 : The data in the receipt-data property was malformed

javascript - 页面加载后在 Firefox 中强制重绘/重绘 DOM 元素

python - 如何返回由 2 个下拉列表更新的数据表作为 Plotly Python 中的输入

python - Python 的 VS 代码中的 "Debug Adapter Executable not provide"

python - 当滚动条已设置时更新 WheelEvent 上的 QLineEdit

javascript - href=javascript : jquery not working in FF

html - 如何禁止 Firefox 将我所有的颜色值转换为 rgb?

python - 将 keras 模型的损失集成到 tensorflow 图中

c# - 如何在测试期间伪造 Startup.cs 中声明的服务?

testing - 在一个奴隶的项目之间共享工件