python-3.xselenium-webdriverxpathseleniumbase

SeleniumBase - Unable to select a value from a dropdown using value, text,index


I am working on automating my workflows in SeleniumBase + Python. I am facing issues with this specific webpage , where I want to click on the dropdown and choose a value from the list of options presented to us.

I have tried using the methods :

self.click('//*[@id="-1_PersonProfileFields.AddressCountry"]')
self.send_keys("India")
self.select_option_by_index("//*[@id='-1_PersonProfileFields.AddressCountry']",45)
self.click('select#-1_PersonProfileFields.AddressCountry')
self.send_keys("India")

However , I face NoSuchElementException errors with each method.

The entire code is mentioned below :

from seleniumbase import BaseCase,Driver
import time
BaseCase.main(__name__, __file__)

class MyTestClass(BaseCase):
    def test_demo_site(self):
      self.get("https://careers-se.icims.com/jobs/67282/area-sales-manager---distributor/candidate?from=login&eem=VALI7WbuYjsYNVeTcJFe1Lp4NyzhJKL%252BgGk896dMArDy6SnRigcgxLtwQv3zbEEv&code=d4da33efe18fb5649da3012875a78ef45945b558aebf7cc0ab3716dce83614e7&ga=c2c2d57aa55f3a4b29a0cfc15e12e9e57cc3deaa024a3a5bc8be5724f93cc0b2&accept_gdpr=1&gdpr_consent_type=37002057002")
      time.sleep(5)
      self.switch_to_frame_of_element("//*[@id='PersonProfileFields.FirstName']")
      self.type("//*[@id='PersonProfileFields.FirstName']","Saul")
      time.sleep(10)
      self.select_option_by_index("//[@id='-1_PersonProfileFields.AddressCountry']",45)
      input("Continue")

Please let me know where I have made the mistake and how to rectify them.

Thank You !


Solution

  • Here's the https://github.com/seleniumbase/SeleniumBase script for that:

    from seleniumbase import BaseCase
    BaseCase.main(__name__, __file__)
    
    class MyTestClass(BaseCase):
        def test_career_page(self):
          self.get("https://careers-se.icims.com/jobs/67282/area-sales-manager---distributor/candidate?from=login&eem=VALI7WbuYjsYNVeTcJFe1Lp4NyzhJKL%252BgGk896dMArDy6SnRigcgxLtwQv3zbEEv&code=d4da33efe18fb5649da3012875a78ef45945b558aebf7cc0ab3716dce83614e7&ga=c2c2d57aa55f3a4b29a0cfc15e12e9e57cc3deaa024a3a5bc8be5724f93cc0b2&accept_gdpr=1&gdpr_consent_type=37002057002")
          self.switch_to_frame("#icims_content_iframe")
          self.type("//*[@id='PersonProfileFields.FirstName']", "Saul")
          self.click('a span[id*="Fields.AddressCountry"] span')
          self.type('[id*="Fields.AddressCountry"] input', "India")
          self.click('[id*="Fields.AddressCountry"] li[title="India"]')
    
          breakpoint()
    

    I did some optimization too. I'm the maintainer of SeleniumBase, so I know a few things. :)