Home > Software design >  Introducing Name in Search Field of Google Play Store using Selenium
Introducing Name in Search Field of Google Play Store using Selenium

Time:08-30

I'm trying to search for an App Name in the Google Play Store. For this I have to click on the Lens button on the upper right to make it appear, then introduce the name.

My approach for this is the following, but I had no luck with it. I tried using other selectors but I'm not sure if I'm picking the correct one (I'm not experienced with Selenium).

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://play.google.com/store")
driver.find_element_by_css_selector('VfPpkd-Bz112c-Jh9lGc').click()
inputElement = driver.find_element_by_id("oA4zhb")
inputElement.send_keys('some app name')

Has anyone done this successfully that can provide orientation to make this code fulfill its purpose?

Thanks in advance.

CodePudding user response:

Cross check locators used..

to click on search icon you can use

By.xpath("//button/i[contains(.,'search')]")

to input in search box use

//input[@aria-label='Search Google Play']

CodePudding user response:

VfPpkd-Bz112c-Jh9lGc is not a valid CSS selector for the search icon unless that's an element name (which it isn't). That's actually a class name so the CSS selector would be .VfPpkd-Bz112c-Jh9lGc, note the added period at the start which indicates a class name. If you refresh the page a few times you will see that the class changes name so that tells you it's not going to be useful in a locator. You need to find something that never changes. Ideally it would have an ID or name but it has neither. I would use the CSS selector, button[aria-label="Search"].

Once the search box is open you need to locate it. Your code is looking for an ID of "oA4zhb" but if you look at the HTML, you'll see that INPUT doesn't have an ID. You are referencing the jsname attribute. That may or may not be stable, I'm not sure. I would use the CSS selector, input[aria-label="Search Google Play"].

Putting the code together

driver = webdriver.Firefox()
driver.get("https://play.google.com/store")
driver.find_element_by_css_selector('button[aria-label="Search"]').click()
driver.find_element_by_css_selector('input[aria-label="Search Google Play"]').send_keys('some app name')
  • Related