Reputation: 521
I am using selenium and its WebDriver API to do a quick google search for something.
The examples that are usually given include this:
driver.get("https://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese");
element.submit();
Apparently this will search for 'Cheese' in google. But I'm not sure where they got 'q' from or how it relates to google's search bar?
Thanks
Upvotes: 0
Views: 428
Reputation: 6950
Inspect the html of the search bar in google search page. And this is what you get -
<input class="gsfi" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Search" type="text" value="" aria-label="Search" aria-haspopup="false" role="combobox" aria-autocomplete="both" dir="ltr" spellcheck="false" style="border: none; padding: 0px; margin: 0px; height: auto; width: 100%; position: absolute; z-index: 6; left: 0px; outline: none; background: url(data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D) transparent;">
From here you can see different attributes like name etc.
Upvotes: 1