1

I have tried many possible situations but I can't access it kindly help me out in this how I can click on common-home res layout-home1 loaded hidden-scroll modal-open here I want to click on (add to cart) and (wishlist ) my code is below

    from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from time import sleep
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException


driver = webdriver.Chrome(executable_path='C:\Program Files\JetBrains\PyCharm 2021.1.1/chromedriver.exe')


driver.maximize_window()
driver.get("http://esindbaad.com/")
#mouse hour to catagories
beauty = driver.find_element_by_xpath("//*[@id='head-wrapper']/div/div/div/div/ul/li[3]/a")
body = driver.find_element_by_xpath("//*[@id='head-wrapper']/div/div/div/div/ul/li[3]/div/div/div/div/div/div[1]/div[3]/div/ul/li[6]/a")
actions = ActionChains(driver)
actions.move_to_element(beauty).move_to_element(body).click().perform()
#add to wishlist

wish = driver.find_element_by_xpath("//*[@id='content']/div/div[1]/div[1]/div/div[1]/div/button[1]/i")
actions = ActionChains(driver)
actions.move_to_element(wish).click().perform()
#click and view product
product = driver.find_element_by_xpath("//*[@id='content']/div/div[1]/div[1]/div/div[1]/div/a")
actions = ActionChains(driver)
actions.move_to_element(product).click().perform()
# product added to cart button click
driver.switch_to.frame(iframe)
addcart = driver.find_element_by_id("button-cart")
actions = ActionChains(driver)
actions.move_to_element(addcart).click().perform()

wishlist = driver.find_element_by_xpath("//*[@id='product']/div[2]/div[3]/ul/li/a")
actions = ActionChains(driver)
actions.move_to_element(wishlist).click().perform()




driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")

1 Answer 1

1

wait for the window to appear before clicking it using explicit wait

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

addcart = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, "button-cart")))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.