gpt4 book ai didi

python - xPath 不进入下一页

转载 作者:行者123 更新时间:2023-11-28 20:26:09 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com