Python xPath不';I don’我不能进入下一页
当我使用下面的代码时,网站不会进入下一页Python xPath不';I don’我不能进入下一页,python,testing,firefox,selenium-webdriver,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 set
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不起作用时,我要做的第一件事就是检查它,通常使用类似于xpath的扩展来确保它是正确的。此外,最好使用较短的xpath,以减少出错的空间,即
“//img[@title='Printed Dress']”
尝试以下xpath并使用javaScript executor单击快速查看
此代码将单击页面上的第一个元素。如果您希望依次单击所有Quick Viw
按钮,则需要进一步编写逻辑
driver.get("http://automationpractice.com/index.php")
driver.maximize_window()
ele_Quikview=driver.find_element_by_xpath('(//a[@class="quick-view"])[1]')
driver.execute_script("arguments[0].click();",ele_Quikview)