0

The Problem

In Chrome, I'm attempting to select a search button via a Selenium method in Python and have the new content load on the same tab without opening in a new tab. However, when running through Selenium methods, the content always loads in a new tab. When operating as a human user, the button click always results in the new content loading on the same page.

EDIT: The URL (for reference, and since I'm not very good at using the Chrome dev tools to debug Javascript) is https://glassdoor.com. This is for a personal development project, in case anyone is curious.

What I've Tried

This is in Python 2.7.16 with the Selenium Webdriver module. I have tested the following methods on this button:

.click()

.sendKeys(Keys.ENTER)

I've also tried WebDriverWait(driver, X.0) prior to selecting the button to accommodate for DOM refreshes.

I am 90% certain that this is behaving the way it is because the search button doesn't receive a target until after it has been pressed by the user. The target link is generated through a Javascript function that builds the link based off of the keywords.

Additionally, this is the only thread I could find where a similar question was asked. Unfortunately, that person had a target property they could manipulate.

The Code

The current Python code/Selenium method to click the button:

#The .click() and .send_keys(Keys.ENTER) methods work the same from my experience

chromeDriver.find_element_by_id("HeroSearchButton").send_keys(Keys.ENTER)

HTML as seen in Chrome Console:

<button class="gd-btn-mkt" id="HeroSearchButton" type="submit" tabindex="0"><span>Search</span></button>
    ::before
    <span>Search</span>
    ::after
</button>
ffej
  • 73
  • 2
  • 7
  • Can you share your url? – KunduK Sep 16 '19 at 13:46
  • Sure! It's https://glassdoor.com - will update the post. Wasn't sure if sharing a URL like that was breaking rules or not. Thanks! – ffej Sep 16 '19 at 14:11
  • Manual steps to reach the `HeroSearchButton` button? – KunduK Sep 16 '19 at 14:20
  • (1) Open up the website homepage, (2) Select "Companies" in the dropdown, (3) Using the Chrome dev tools "Elements" panel and the element selector (the little square with an arrow inside of it – found in the top left-hand corner of the console), select the green "Search" button to the right of the search bar. – ffej Sep 16 '19 at 14:25
  • Can you try this : `chromeDriver.find_element_by_id("HeroSearchButton").submit()` – KunduK Sep 16 '19 at 15:18
  • I just ran through it, and it still opened the results in a new tab. The submit is a great idea though, because the search bar is nested in a form element. Did it work for you? – ffej Sep 16 '19 at 16:02

0 Answers0