Abhishek Yadav
Abhishek Yadav

Reputation: 107

How to fix the issue as driver.send_keys(Keys.ENTER) is not working

I am able to enter the location, but once I am done with sending the location, then it should automatically click the 1st item from suggestion, but it is not working. Any work around on this?

I have tried almost all the things like inducing some wait time in order to load the suggestion and then press enter but nothing has helped me. I am newbie in selenium and python.

url = 'https://www.stek-usa.com/locator'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(10)
driver.get(url)
loc = driver.find_element_by_id('storelocator-search_address')
loc.send_keys('Arkansas, USA')
loc.click()
loc.send_keys(Keys.RETURN)

Once enter is pressed, it should show the correct location. But that is not happening. Please help me on this.

Upvotes: 1

Views: 702

Answers (2)

Sreenivasulu
Sreenivasulu

Reputation: 514

Try this way: driver.sendKeys(Keys.chord("your location", Keys.ENTER));

This step will perform entering your location into text box and will click on first matching option, which will fulfill your criteria

Upvotes: 0

Mate Mrše
Mate Mrše

Reputation: 8394

Try the following, instead of the last three lines of your code, add this:

loc.send_keys('Arkansas, USA' + Keys.DOWN + Keys.RETURN)

Upvotes: 2

Related Questions