Reputation: 11
When I use below code, the website doesn't go on to the next page.
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)
It should go on to the next page but xPath doesn't work.
Upvotes: 1
Views: 117
Reputation: 33384
Try the following xpath and use javaScript executor to click on Quick View
This code will click 1st element on the page.If you wish to click all Quick Viw
button sequentially you need to write logic further.
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)
Upvotes: 1
Reputation: 108
Hello and good luck on learning test automation.
The first thing I do when an xpath does not work is to check it, usually using an extension like this one to make sure it is correct. Additionally, it is better to use a shorter xpath so there is less room for mistake i.e. "//img[@title='Printed Dress']"
Upvotes: 1