0

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.

Abhinav Singh
  • 31
  • 1
  • 6
  • 1
    i think it should be `EC.element_to_be_clickable((By.XPATH, 'xpath_goes_here'))` instead of `EC.element_to_be_clickable(By.XPATH, 'xpath_goes_here')`. Both the elements should eb in a tuple i guess – Ghost Ops Apr 01 '22 at 07:43
  • Thanks for both the comment and the answer. But I think you people didn't read the question. I want to click on it but I am not able to that's what I am asking. Please help – Abhinav Singh Apr 01 '22 at 09:46
  • undetected Selenium has explained it clearly in his answer, check [it](https://stackoverflow.com/a/71704770/16693888) out – Ghost Ops Apr 01 '22 at 09:50

3 Answers3

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

buzzbuzz
  • 209
  • 1
  • 3
  • Thanks for both the comment and the answer. But I think you people didn't read the question. I want to click on it but I am not able to that's what I am asking. Please help – Abhinav Singh Apr 01 '22 at 09:46
  • This is exactly the problem, `EC.element_to_be_clickable(By.XPATH, 'html/body/div/div/div[3]/div[2]/div[12]/div[1]/div/div/div[2]/div')` cannot find the element because you are passing wrong arguments, no click is performed. It is clearly stated in the error message. Have you actually try the code? – buzzbuzz Apr 01 '22 at 10:08
  • I acutally tried it. It didn't work. – Abhinav Singh Apr 02 '22 at 08:29
  • What is the error message? – buzzbuzz Apr 03 '22 at 10:57
  • Can't locate element. My question is how can I locate the element check the url plz. – Abhinav Singh Apr 24 '22 at 12:00
0

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()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

I also encountered a similar problem, which is currently solved by time.sleep.

my guess is that seleniumwire.webdriver did some unknown patch that caused WebDriverWait to fail.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 25 '22 at 06:49
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32547963) – pigrammer Aug 29 '22 at 17:34