[Python] Button press TAB not working in selenium python

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a script, which would share a particular post along some groups in Facebook.
    Everything is working smoothly, until choosing the group to repost the post in.

    I have decided to use search bar and pressing TAB + ENTER after the search to proceed with the first available option after the search

    Testing this manually works, I search for the group, then press tab + enter and the first group is chosen, only publishment is required after.

    But trying to do so with Selenium doesn't work.
    I can see how the scipt presses TAB, but shortly after, the search bar is being active again, so pressing ENTER doesn't do anything.

    try:
    group_input = driver.find_element(
    By.XPATH, '//input[contains(@placeholder, "груп") or contains(@placeholder, "group")]'
    )
    group_input.clear()
    group_input.send_keys(group_name)

    WebDriverWait(driver, 10).until(EC.presence_of_element_located(
    (By.XPATH, '//input[contains(@placeholder, "груп") or contains(@placeholder, "group")]')
    ))
    time.sleep(2)

    group_input.send_keys(Keys.TAB)
    time.sleep(1)
    group_input.send_keys(Keys.ENTER)
    time.sleep(2)


    I cannot really understand what is the issue here, how can I do so the group after searching is selected?

    I tried switching by simulating the mouse click, tried to do so with execution with js script, but seems like selenium is struggling with not static elements.
    I am expecting the script not making the search bar active again after pressing tab.

    Continue reading...

Compartilhe esta Página