-1

I have a problem in my code.

 for photolink in all_links:

        self.browser.get(photolink)         #Link öffnen
        time.sleep(random.randint(5, 6))

        #liken
        self.browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div/div[2]/div/div[2]/section[1]/span[1]/button').click()
        time.sleep(random.randint(1, 3))

        #kommentieren
        commentbox = self.WaitforObject(By.CLASS_NAME,"Ypffh")
        commentbox.click()
        time.sleep(random.randint(1, 2))

        #commentbox.send_keys(self.config.Random_Comment())
        commentbox.send_keys("Test")
        commentbox.send_keys(Keys.ENTER)
        time.sleep(random.randint(3, 5))

        c = c + 1
        print("Liked ", c, " photos")

    time.sleep(random.randint(1, 3))

It works until commentbox = self.WaitforObject(By.CLASS_NAME,"Ypffh"), so the curser is in the textfield. But, when I want to write something with send_keys, it broke.

Screenshot

Ali_Sh
  • 2,667
  • 3
  • 43
  • 66
  • There are multiple reasons of not working if someone will try to figure it out from the question. But you can narrow down those reasons by mentioning the exact error message in your console. It might be something like, Timeout Exception, NoSuchElementExxception etc. – QualityMatters Nov 29 '21 at 14:07
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 04 '21 at 16:18

1 Answers1

0
  1. Make sure you have imported the keys library from selenium

    from selenium.webdriver.common.keys import Keys

  2. use find element by xpath (if you use xpath to send keys you dont have to click onto it first)

    commentbox = self.browser.find_element_by_xpath("xpath here")

    commentbox.send_keys("blah blah blah")

You may also have to click on the post button instead of using Keys.ENTER

Lobstergoat
  • 113
  • 1
  • 9