1

I wand to get feedbacks from page url = 'https://ru.aliexpress.com/store/product/Gillette-Fusion-blade-4-pc/2671035_1000003578539.html?spm=2114.12010612.0.0.xL0ySy'

I wait until page loaded. And I can find elements using Google Chrome inspector. But selenium can't find elements. And I alse can't find elements at the source page.

How can i get feedbacks using selenium or other instruments?

Here is my code:

from selenium import webdriver
import time
import csv
import requests

url = 'https://ru.aliexpress.com/store/product/Gillette-Fusion-blade-4-pc/2671035_1000003578539.html?spm=2114.12010612.0.0.xL0ySy'
driver = webdriver.Chrome()
driver.get(url)

try:
    close_popup = driver.find_element_by_class_name('close-layer')
    close_popup.click()
except:
    print("no alert")


tab_feedback = driver.find_element_by_xpath('//*[@id="j-product-tabbed-pane"]/ul/li[2]')
tab_feedback.click()
time.sleep(8)
try:
    text_feedback = driver.find_element_by_xpath('//*[@id="transction-feedback"]/div[4]/div[1]/div[2]/div[3]/dl')
    print(text_feedback.text)
except:
    print("cant find by xpath")

try:
    text_feedback = driver.find_element_by_class_name('buyer-feedback')
    print(text_feedback.text)
except:
    print("cant find by class_name")


try:
    text_feedback = driver.find_element_by_css_selector('div.f-content.dl.dt.span')
    print(text_feedback.text)
except:
    print("cant find by css_selector")

it returns:

cant find by xpath
cant find by class_name
cant find by css_selector

2 Answers 2

2

You can try to add ExcplicitWait as below to wait for presence of required element:

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

text_feedback = wait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "buyer-feedback"))).text

Also note that element located inside an iframe, so you should switch to it first before handling embedded elements:

driver.switch_to.frame(driver.find_element_by_xpath('//iframe[starts-with(@src, "//feedback.aliexpress.com/display/productEvaluation.htm")]'))

To switch back from iframe:

driver.switch_to.default_content()

As for your selectors:

  • You should avoid using XPath expressions like //*[@id="transction-feedback"]/div[4]/div[1]/div[2]/div[3]/dl, but use more verbose relative XPath, like //dl[@class="buyer-feedback"] instead
  • CSS selector div.f-content.dl.dt.span should match element <div class="f-content dl dt span">. Note that you should use space to point on descendant element (div dt) and ">" to point on direct child (div>dl). Your CSS selector might looks like div.f-content>dl>dt>span or div.f-content dt>span...
Sign up to request clarification or add additional context in comments.

4 Comments

it raise TimeoutException(message, screen, stacktrace). I am sure that problem not in speed of selenium. I tried to wait several minutes and looping requests. But it still doesn't find elements
Yes. It located inside iframe. Check updated answer
Thanks, i got it =). Only one question. Where did you find xpath of Iframe?
Just check ancestors and you'll find <iframe scrolling="no" marginwidth="0" marginheight="0" src="//feedback.aliexpress.com/display/productEvaluation.htm?productId=1000003578539&ownerMemberId=825321852&companyId=&memberType=seller&startValidDate=" width="100%" height="1910" frameborder="0">. I don't use tools for generating XPath. If you want to write your own XPath expressions, you might check tutorialspoint.com/xpath/xpath_overview.htm
0

And I also can't find elements at the source page.

This is OK since lots of modern websites uses dynamically loaded content and AJAX and JS frameworks. The source page is just the initial DOM nothing is added.

However the inspector refreshes its DOM. You should look for how to find dynamically added element to DOM.

2 Comments

I always thought that selenium can handle Ajax. It can work like real user
Maybe selenium is too quick, check answer below or implement a retry mechanism (loop, sleep, retry, sleep more, retry, etc)

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.