Can it really be true, that I'm not allow to click this button??
From https://www.gettyimages.dk/search/2/image?phrase=lfc The link can also be in format of https://www.gettyimages.dk/photos/lfc?assettype=image&phrase=lfc&sort=mostpopular&license=rf,rm&page=1 . I dont know what is the difference between the two. I have only tried with https://www.gettyimages.dk/search/2/image?phrase=lfc. Can that be the reason why I'm having dificulties clicking the button?
CSS-Selector 1
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > div.content_wrapper > section > div > main > div > div > div:nth-child(4) > div.Gallery-module__columnContainer___LqU0P > section > a'))).click()
Error:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a title="Next page" rel="next">...</a> is not clickable at point (677, 23). Other element would receive the click: <input data-testid="container-search-box-input" placeholder="Search the world’s best photos and images" aria-label="text" name="phrase" autocomplete="off" data-autosuggest-from="https://as.gettyservices.com:443/GettyImages.Autocomplete.KeywordService.Service/KeywordService1/Suggestedkeywords/{0}/{1}/{2}/{3}/{4}?usePopularity=true" value="lfc">
CSS-Selector 2
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > div.content_wrapper > section > div > main > div > div > div:nth-child(4) > div.Gallery-module__columnContainer___LqU0P > section > a > div'))).click()
Error: selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div >...</div> is not clickable at point (673, 9). Other element would receive the click: <div data-testid="container-search-box">...</div>
CSS-Selector 3
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > div.content_wrapper > section > div > main > div > div > div:nth-child(4) > div.Gallery-module__columnContainer___LqU0P > section > a > svg'))).click()
Error:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <svg xmlns="http://www.w3.org/2000/svg" width="8.233" height="13.861" viewBox="0 -4.861 8.233 13.861" >...</svg> is not clickable at point (703, 7). Other element would receive the click: <div data-testid="container-search-box">...</div>
(Session info: chrome=103.0.5060.134)
CSS-Selector 4
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'body > div.content_wrapper > section > div > main > div > div > div:nth-child(4) > div.Gallery-module__columnContainer___LqU0P > section > a > svg > path'))).click()
Error:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <path d="M8.233 2.018L1.251 9 0 7.645l5.627-5.627L0-3.61l1.251-1.25 6.982 6.878z"></path> is not clickable at point (703, 7). Other element would receive the click: <div data-testid="container-search-box">...</div>
(Session info: chrome=103.0.5060.134)
Xpath 1
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a'))).click()
Error: selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a title="Next page" rel="next">...</a> is not clickable at point (677, 23). Other element would receive the click: <input data-testid="container-search-box-input" placeholder="Search the world’s best photos and images" aria-label="text" name="phrase" autocomplete="off" data-autosuggest-from="https://as.gettyservices.com:443/GettyImages.Autocomplete.KeywordService.Service/KeywordService1/Suggestedkeywords/{0}/{1}/{2}/{3}/{4}?usePopularity=true" value="lfc">
Xpath 2
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a/div'))).click()
Error : selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div >...</div> is not clickable at point (673, 9). Other element would receive the click: <div data-testid="container-search-box">...</div>
Xpath 3
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a/svg'))).click()
Error: WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a/svg'))).click()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 90, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Xpath 4
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a/svg/path'))).click()
Error: WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[2]/section/div/main/div/div/div[4]/div[2]/section/a/svg/path'))).click()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 90, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
CodePudding user response:
Try either of the following css selector
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[title='Next page']"))).click()
OR
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[title='Next page'][rel='next']"))).click()
OR
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[title='Next page'][class^='PaginationRow-module__button']"))).click()
If it is still giving error, you might have to use javascript executor to scroll first and then click.
driver.execute_script ("arguments[0].click();",WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[title='Next page']"))))
CodePudding user response:
To click on the element NEXT instead of visibility_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[title='Next page']>div"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='NEXT']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC