0
votes

Could you make an example with the site? I want to ignore the posts with comments and just click the ones without comments.

from selenium import webdriver
import time

path = "C:\chromed\chromedriver.exe"
driver = webdriver.Chrome(path) #path
'''

'''
driver.get("http://cineaste.co.kr/") #url
time.sleep(0.5)

postclick = driver.find_element_by_xpath("//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]") #로그인창 활성화
postclick.click()


driver.close()

I tried this, but there was an error.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]"}
  (Session info: chrome=81.0.4044.138)

I want to click on a post that doesn't have any comments yet. And I want to skip posts with comments. I'm still a beginner. Help me.

2

2 Answers

0
votes

The Element you are looking for is not available. You need to recreate the Xpath. The Xpath you created is incorrect. See following image :-Xpath you enetered

0
votes

You'll need these imports :

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

Example with the first entry with no comments in the "movie-reviews" block :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h3[.='영화감상평']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))][1]"))).click()

MR