1

I am trying to get the review of a certain product but it returns an error.

My code:

import selenium
from selenium import webdriver
chrome_path = r"C:\Users\AV\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)

driver.get("https://oldnavy.gapcanada.ca/browse/product.do?pid=647076053&cid=1180630&pcid=26190&vid=1&nav=meganav%3AWomen%3ADeals%3ASale&grid=pds_0_1034_1#pdp-page-content")
driver.execute_script("window.scrollTo(0, 1000)")
import time
from time import sleep
sleep(5)
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.promoDrawer__handlebar__icon"))).click()

review = driver.find_elements_by_class_name("pr-rd-description-text")
for post in review:
    print(post.text)
    
driver.find_element_by_xpath('//*[@id="pr-review-display"]/footer/div/div/a').click()
review2 = driver.find_elements_by_class_name("pr-rd-description-text")
for post in review2:
    print(post.text)

It returns: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Can you please tell me what should I do?

2 Answers 2

2

The button is really hard to click.

I guess it could be achieved by adding some more waits and moving with ActionChains class methods.

I could click it with Javascript code with no problems. What it does:

1 Scrolls to the Next button

2 Clicks it.

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

driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')

driver.get(
    "https://oldnavy.gapcanada.ca/browse/product.do?pid=647076053&cid=1180630&pcid=26190&vid=1&nav=meganav%3AWomen%3ADeals%3ASale&grid=pds_0_1034_1#pdp-page-content")
driver.execute_script("window.scrollTo(0, 1000)")

wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.promoDrawer__handlebar__icon"))).click()
wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".pr-rd-description-text")))
review = driver.find_elements_by_css_selector(".pr-rd-description-text")
for post in review:
    print(post.text)

# wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".pr-rd-pagination-btn"))).click()
element = driver.find_element_by_css_selector(".pr-rd-pagination-btn")

# actions = ActionChains(driver)
# actions.move_to_element(element).click().perform()
driver.execute_script("arguments[0].scrollIntoView();", element)  # Scrolls to the button
driver.execute_script("arguments[0].click();", element)  # Clicks it
print("clicked next")

I also rearranged your code, moved imports to the beginning of the file, got rid of unpredictable time.sleep() and used more reliable css locators. However, your locator should also work.

I left the options I tried commented out.

Sign up to request clarification or add additional context in comments.

3 Comments

Weird. It doesn't work for me, I still get the element not interactable error if I try element.click(), and running your code does not actually click the button.
@C.Peck Do you see any error when running my code? I just checked it again three times and the button was clicked. You can verify it if you check the paging.
after several attempts this works for me: driver.execute_script("arguments[0].scrollIntoView();", element) # Scrolls to the button driver.execute_script("arguments[0].click();", element) # Clicks it
2

That element is weird. Even when I scroll into view, use actions to click it, or execute javascript to click, it doesn't work. What I would suggest is just grabbing the href attribute from the element and going to that URL, using something like this:

driver.get(driver.find_element_by_xpath('//*[@id="pr-review-display"]/footer/div/div/a').get_attribute('href'))

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.