0

I have a problem with a code.

I need to wait for 3 seconds and then click the Follow button.

This code click the Follow button immediately when the website loads.

for follow in accounts_scrapped:
    driver.get(follow)

    try:
        follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']").click()
        print("found follow button")
        follow_button.click()
        print("followed")

    except:
        print("already followed this account. Going to next one")
        continue
7
  • 1
    use time.sleep(3)? Commented Nov 26, 2020 at 12:23
  • didn't change anything. Commented Nov 26, 2020 at 12:25
  • you are clicking the button twice? follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']").click() has .click() at the end Commented Nov 26, 2020 at 12:28
  • and then you done follow_button.click() Commented Nov 26, 2020 at 12:28
  • oops i put it by mistake. I want to click it one time, but not immediately . Commented Nov 26, 2020 at 12:30

1 Answer 1

1

Debug your code like this, this may help see where the problem is then

for follow in accounts_scrapped:
    driver.get(follow)
    try:
        follow_button = driver.find_element_by_xpath("//span[text() = 'Follow']")
        time.sleep(3)
        print('0 seconds letf')
        follow_button.click()
        print("followed")
    except Exception as e :
        print(e)
        print("already followed this account. Going to next one")
        continue

print(e) will print the error

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

8 Comments

are you saying its not waiting 3 seconds? maybe somewhere else in your code you've clicked it?
I'am always getting the message "already followed this account. Going to next one"
that means the try block had an error so it moved to the except block
what's being printed out for print(e)?
the time.sleep(3) as i understand waits 3 seconds until the next page appears. But in this case it clicks immediately the Follow button again when every page of the website appears.
|

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.