Home > other >  python selenium webdriver : click 'read more'
python selenium webdriver : click 'read more'

Time:01-30

inspect > elements

for scarping website(TripAdvisor), i wanted to click 'read more' by using selenium webdriver and scraping full reviews. I tried 5 scripts as below but anything didn't work. Please let me know the right answer

driver.find_elements_by_css_selector("dlJyA")[0].click()
driver.find_element_by_xpath("//div[@class='dlJyA']").click()
driver.find_element_by_xpath("//span[contains(@class,'eljVo _S Z')]").click()
driver.find_element_by_xpath("//div[@class='dlJyA']/span[@class='eljVo _S Z')]").click()
driver.find_element_by_class_name('eIVRK').click()

and the CSS was of website was

<div  style="line-height: 20px;">  <div  data-test-target="expand-review">   <span >Read more</span>   <span >   </span>  </div> </div>

CodePudding user response:

I think you should install this chrome extension to select exactly xpath https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo?hl=en

CodePudding user response:

You should wait for the page to load first, using implicitly_wait

driver.implicitly_wait(3)

Code:

driver.implicitly_wait(3)
driver.find_element_by_class_name('eIVRK').click()
  •  Tags:  
  • Related