How to select from address using selenium and python?



  • I am automating make my trip app for practicing. I am working on selenium and python
    I am unable to enter from the address and select the autocomplete list.

    here is the code

    import unittest
    from selenium import webdriver
    
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    class PythonOrgSearch(unittest.TestCase):
    
        def setUp(self):
            self.driver = webdriver.Chrome()
    
        def test_search_in_python_org(self):
            driver = self.driver
            driver.get("https://www.makemytrip.com")
            fromaddress = driver.find_element_by_class_name('react-autosuggest__input react-autosuggest__input--open')
            fromaddress.send_keys('Bangalore')
            fromaddress.send_keys(Keys.ARROW_DOWN)
            fromaddress.send_keys(Keys.RETURN)
    
    
    
    
        def tearDown(self):
            self.driver.close()
    
    if __name__ == "__main__":
        unittest.main()
    

    enter image description here



  • You first have to open the menu, by clicking on the From City text, using ID.

    driver.find_element_by_id("fromCity").click()
    

    Then you can query the autocomplete, but fixing the locator you used (only one class is necessary):

    driver.find_element_by_css_selector(".react-autosuggest__input--open")
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2