1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How do I find the correct selenium locator for search input box

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024 às 14:12.

  1. Stack

    Stack Membro Participativo

    I am trying to automate searching food on swiggy but I am getting error when I try to automate the search inputbox. I am using SelectorsHub to find the locators but still I am facing issues. I am getting the following output in my terminal

    code snippet:

    from selenium import webdriver
    import time

    from selenium.webdriver import Keys
    from selenium.webdriver.common.by import By

    browser = webdriver.Chrome()
    browser.get('https://google.com')
    browser.maximize_window()

    search = browser.find_element(By.XPATH, "//textarea[@id='APjFqb']")
    search.send_keys("Swiggy")
    search.send_keys(Keys.RETURN)

    site = browser.find_element(By.PARTIAL_LINK_TEXT, "Swiggy")
    site.click()

    search_btn = browser.find_element(By.XPATH, "//span[normalize-space()='Search']")
    search_btn.click()

    search_food = (browser.find_element(By.CSS_SELECTOR, 'button[class*="SearchButton"]'))
    search_food.click()

    time.sleep(10)


    Error:

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@placeholder='Search for restaurants and food']"}
    (Session info: chrome=123.0.6312.107); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
    Stacktrace:
    GetHandleVerifier [0x00007FF713927032+63090]
    (No symbol) [0x00007FF713892C82]
    (No symbol) [0x00007FF71372EC65]
    (No symbol) [0x00007FF71377499D]
    (No symbol) [0x00007FF713774ADC]
    (No symbol) [0x00007FF7137B5B37]
    (No symbol) [0x00007FF71379701F]
    (No symbol) [0x00007FF7137B3412]
    (No symbol) [0x00007FF713796D83]
    (No symbol) [0x00007FF7137683A8]
    (No symbol) [0x00007FF713769441]
    GetHandleVerifier [0x00007FF713D225AD+4238317]
    GetHandleVerifier [0x00007FF713D5F70D+4488525]
    GetHandleVerifier [0x00007FF713D579EF+4456495]
    GetHandleVerifier [0x00007FF713A00576+953270]
    (No symbol) [0x00007FF71389E54F]
    (No symbol) [0x00007FF713899224]
    (No symbol) [0x00007FF71389935B]
    (No symbol) [0x00007FF713889B94]
    BaseThreadInitThunk [0x00007FFC9DBB257D+29]
    RtlUserThreadStart [0x00007FFC9F24AA48+40]

    Continue reading...

Compartilhe esta Página