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.

3
  • 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 Commented Apr 1, 2022 at 7: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 Commented Apr 1, 2022 at 9:46
  • undetected Selenium has explained it clearly in his answer, check it out Commented Apr 1, 2022 at 9:50

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

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
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?
I acutally tried it. It didn't work.
What is the error message?
Can't locate element. My question is how can I locate the element check the url plz.
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()

3 Comments

I tried it does not work.
My bad, there was a typo fixed it now. Let me know the result.
Doesn't work. Please try to run the code if you can then you will see that the element is not being located. And I guess it is dynamic. And thank you for all your responses.
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.

2 Comments

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.
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.