'The element doesn't load and selenium is not able to click
I am working on a anime scraper if you have read my previous questions you would know. I tried scraping fmbed but failed so started scraping the original page. Here I am not able to click on the element. The code-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from seleniumwire import webdriver
# Chrome Stuff
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
url = 'https://gogoanime.fi/shingeki-no-kyojin-the-final-season-part-2-episode-7'
driver.get(url)
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable(By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div')).click()
driver.implictly_wait(5)
for request in driver.requests:
if request.response:
print(request.url)
# print(request.response.headers)
driver.quit()
driver.close()
The console -
Traceback (most recent call last):
File "/home/zenitsu/PycharmProjects/anistreamsrc/main.py", line 20, in <module>
wait.until(EC.element_to_be_clickable(By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div')).click()
TypeError: element_to_be_clickable() takes 1 positional argument but 2 were given
Process finished with exit code 1
Please help me. I will be glad to hear any comments.
Solution 1:[1]
You should do wait.until(EC.element_to_be_clickable((By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div'))).click()
(By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div') should be passed as a tuple, not separate arguments
Solution 2:[2]
This error message...
wait.until(EC.element_to_be_clickable(By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div')).click()
TypeError: element_to_be_clickable() takes 1 positional argument but 2 were given
...implies that the while invoking WebDriverWait you have used a wrong format.
As @Ghost Ops mentioned in their comments you need to pass both the arguments in a tuple. So effectively, your line of code will be:
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, '//html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div'))).click()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | buzzbuzz |
| Solution 2 |
