Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
5.1k views
by
edited by

Steps to recreate

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as W
from selenium.webdriver.support import expected_conditions as E
import time
driver = webdriver.Chrome(executable_path=r"C:\Users\Ratna Sinha\Downloads\chromedriver_win32\Chromedriver.exe")
driver.maximize_window()
url= "http://practice.automationtesting.in"
driver.get(url)
wait_timeout = 15
wait_variable = W(driver,wait_timeout)
driver.find_element_by_xpath("//a[text()='Shop']").click()
driver.find_element_by_xpath("//a[text()='Home']").click()
driver.execute_script("window.scrollBy(0,50)",'')
items = []
items = driver.find_elements_by_xpath("//li/a/h3")
print(len(items))
assert len(items) == 3
for item in items:
    print(item.text)
    #item.find_element_by_xpath("parent::a/child::img").click()

sliders = []
sliders = driver.find_elements_by_xpath("//div[@id='n2-ss-6']/div/div/div/div/div/img")
assert (len(sliders)) == 3
driver.find_element_by_xpath("//li/a/h3/parent::a/child::img").click()
driver.find_element_by_xpath("//li/a[text()='Description']").click()
driver.execute_script("window.scrollBy(0,70)",'')
time.sleep(3)
assert  driver.find_element_by_xpath("//div[@id='tab-description']/h2").text == "Product Description"
time.sleep(3)
driver.find_element_by_xpath("//div/ul/li[2]/a").click()
time.sleep(3)
assert driver.find_element_by_xpath("//div[@id='comments']/h2").text == "Reviews"
driver.find_element_by_xpath("//button[@type='submit']").click()
driver.find_element_by_xpath("//input[@type='number']").click()
time.sleep(3)
driver.find_element_by_xpath("//button[@type = 'submit']").click()
carttext = driver.find_element_by_css_selector("span.cartcontents").text
print(carttext)
booktitle = driver.find_element_by_xpath("//div/h1").text
driver.find_element_by_xpath("//div[@id ='content']/div/a").click()
booktitle2 = driver.find_element_by_xpath("//tr/td[3]").text
assert booktitle == booktitle2
pricebefcoupon = driver.find_element_by_xpath("//strong/span").text
print(pricebefcoupon)
driver.find_element_by_name("coupon_code").send_keys("krishnasakinala")
driver.find_element_by_name("apply_coupon").click()
priceafcoupon = driver.find_element_by_xpath("//strong/span/span").text
print(priceafcoupon)
driver.find_element_by_xpath("//input[@type ='number']").clear()
driver.find_element_by_xpath("//input[@type ='number']").send_keys(0)
wait_variable.until(E.element_to_be_clickable((By.XPATH,"//tbody/tr[2]/td/input[@name ='update_cart']"))).click()
#wait_variable.until(E.element_to_be_clickable((By.XPATH,"//tbody/tr/following-sibling::tr/td/input[2]"))).click()
subtotal = driver.find_element_by_xpath("//td[@data-title='Subtotal']/span").text
print(subtotal)

Error message:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="submit" class="button" name="update_cart" value="Update Basket"> is not clickable at point (1226, 293). Other element would receive the click: <td class="product-subtotal" data-title="Total">...</td>

 

Why is wrong with my Xpath? why is an element that is in the previous row in the table receiving click? Please help. What am I doing wrong? why is an element that is in the previous row getting click

 

1 Answer

0 like 0 dislike
by Master (1.2k points)

Can you try using only,

 

wait_variable.until(E.element_to_be_clickable((By.XPATH,"//input[@name ='update_cart']"))).click()

and not the complete xpath from //table onwards

by Contributing Tester (30 points)
edited by
Thanks Mayur,
I tried increasing the wait time to up to 600 as you suggested. And got same error when tried with  code :
1. wait_variable.until(E.element_to_be_clickable((By.XPATH,"//tbody/tr[2]/td/input[@name ='update_cart']"))).click()
2.wait_variable.until(E.element_to_be_clickable((By.XPATH,"//input[@name ='update_cart']"))).click()

And timeout Exception with the following code
wait_variable.until(E.element_to_be_clickable((By.XPATH,"//tbody/tr/following-sibling::tr/td/input[2]"))).click()

What should I do now?

Thanks

Ratna
by Master (1.2k points)
Can you try using element by Name instead of XPath?

Something equivalent of,

document.getElementsByName("update_cart")

When I tried the above on my browser console, it works.

I am not in touch with Python, but, you can try this line, or you will have to find some equivalent of it.

wait_variable.until(E.element_to_be_clickable((By.NAME,"update_cart"))).click()


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...