Search code examples
pythonselenium-webdrivercss-selectorswebautomation

Github search bar element not interactable issue


I am trying to use selenium and writing a simple code which will open the browser and go to github website. After opening the page it will search a given keyword in the search bar, but the issue is that when I run the code it is showing the element not interactable. This happening so because I am not being able to find the search bar element probably due to java script code.

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
url = "http://github.com"
driver.get(url)
searchInput = driver.find_element_by_xpath("//*[@id='query-builder-test']")
time.sleep(1)
searchInput.send_keys("python")
time.sleep(2)
searchInput.send_keys(Keys.ENTER)

I tried using javascript executor to select the input element and also used selenium find element method but not being able to search the keyword see here.

element=driver.execute_script("return document.getElementById('query-builder-test').value='python';")
searchInput = driver.find_element_by_xpath("//*[@id='query-builder-test']")

Solution

  • From what i can see the GitHub search bar is a button element. i would suggest:

    driver.maximize_window()
    WebDriverWait(driver, 1)
    search_buttons = driver.find_element(By.CLASS_NAME, "header-search-button")
    print(search_buttons.text)
    search = search_buttons
    search.click()
    

    I would suggest learning some HTML as it makes using Selenium 100x easier

    Hey Here's my updated answer this now clicks on the search bar and should now allow you to type in some text let me know how it goes i tested it out and seems to be working on my end.