Utilize RobotFramework to conduct a Google search for a specific item

I'm having trouble figuring out how to configure my robot framework script to perform a basic Google search.

Here is my code:

*** Settings ***
Documentation                                      This test is very simple
Library                                            Selenium2Library

*** Variables ***
${url}                                              https://www.google.com
${browser}                                          chrome
${text}                                             xpath=//*[@id="lst-ib"]

*** Test Cases ***
User can access website
[Documentation]                                 User should be able to open the 
Google homepage

open browser                                    ${URL}  ${BROWSER}
wait until page contains                        ${url}
close browser

User enters search query
[Documentation]                                 User searches for 'Test 
Definition'

open browser                                    ${URL}  ${browser}
wait until page contains                        ${URL}
input text                                      ${text}  Test Definition
click button                                    btnK
wait until page contains                        Test

Could someone please point out where I've gone wrong?

Answer №1

It seems like the lack of spacing before the keywords was not intentional. Personally, I noticed that only the submit button was using the incorrect path. Therefore, I made a change by adding the close browser step. The example below illustrates how this modification works for me.

*** Settings ***
Documentation                                      Example of a simple test
Library                                            Selenium2Library

*** Variables ***
${url}                                              https://www.google.com
${browser}                                          chrome
${text}                                             xpath=//*[@id="lst-ib"]
${search_button}                                    css=input.lsb

*** Test Cases ***
User opens the page
    [Documentation]                                 User opens the Google homepage
    open browser                                    ${URL}    ${BROWSER}
    wait until page contains                        ${url}
    close browser

User enters text in the search box
    [Documentation]                                 User searches for 'Test Definition'
    open browser                                    ${URL}    ${browser}
    wait until page contains                        ${URL}
    input text                                      ${text}  Test Definition
    click element                                    ${search_button} 
    wait until page contains                        Test
    sleep     5s
    Close Browser

Answer №2

Although I might be arriving late to the party, I have my doubts about the accuracy of your xpath. Instead, consider using CSS as shown below:

*** Variables ***
| ${GoogleBaseUrl} | https://www.google.com/
| ${GoogleForm} | css=form[name=f]
| ${GoogleQuery} | css=input[name=q]

*** KeyWords ***
Open Google Search
    open browser  ${GoogleBaseUrl}    firefox  gl
    wait until element is visible  ${GoogleForm}
    wait until element is visible  ${GoogleQuery}

Make sure to always return to the main page...

Do Google Search
    [Arguments]  ${term}
    log to console  Do Google Search with "${term}"
    switch browser  gl
    go to  ${GoogleBaseUrl}
    wait until element is visible  ${GoogleForm}
    wait until element is visible  ${GoogleQuery}
    input text  ${GoogleQuery}  ${EMPTY}
    input text  ${GoogleQuery}   ${term}
    submit form

Answer №3

If you're looking for an easy fix, consider incorporating a query parameter into the URL.

*** Settings ***

Library     SeleniumLibrary

*** Variables ***

| ${AmazonForm} | css=form[name=f]
| ${AmazonSearchField} | css=input[name=q]
| ${keyword}   | automation
| ${AmazonBaseUrl} | https://www.amazon.com/search?q=${keyword}
*** Test Cases ***
Example test case
    [documentation]  Amazon search test
    [tags]  smoke
    Open Browser  ${AmazonBaseUrl}          chrome  ch

    Close Browser

*** Keywords ***

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for loading extensions in Chrome Driver using Python with Selenium

I have been facing difficulties in opening the Chrome browser with the Browsec extension enabled despite several attempts. Here is what I have tried so far: # Setting up the required command-line option. options = webdriver.ChromeOptions() options.add_argu ...

How to add an item to an array in JavaScript without specifying a key

Is there a way to push an object into a JavaScript array without adding extra keys like 0, 1, 2, etc.? Currently, when I push my object into the array, it automatically adds these numeric keys. Below is the code snippet that I have tried: let newArr = []; ...

In production mode, ExpressJs dispatches the stack efficiently

Before going live, I want to test production simulation with the following setup: package.json "start": "cross-env NODE_ENV=production node dist/index.js", index.ts console.log(process.env.NODE_ENV) // prints "production" ro ...

What is the most reliable way to create an array ensuring that all potential values come from a specific dictionary?

I am seeking a method to define the testArray so that only keys from the example dictionary can be inserted into the array. enum example { key1 = 'A', key2 = 2, key3 = '3', }; const testArray: ?? = [example.key1, example.ke ...

Failed to interpret ratio in Uniswap V3 SwapRouter.swapCallParameters

Following this guide (code), I am attempting a basic trade operation. I have made modifications to some functions in the code to accommodate parameters such as: Token in Token out Amount in The following is my customized createTrade function: export asyn ...

Ways to resolve Boot layer initialization in selenium webdriver

While I am utilizing the selenium webdriver tool for carrying out automation testing, I have encountered a persistent error every time I try to import the safariwebdriver class and Webdriver method. Unfortunately, the error sign remains unresolved. An i ...

Issue with index creation using the @index decorator in Typegoose with NestJS and MongoDB

Encountering an issue with typegoose. Trying to create a 2dsphere index on the property geoLocation of model SP. Utilized the typegoose decorator @index but it's not functioning and not throwing any errors. Uncertain about how typegoose handles this s ...

Looking to retrieve CloudWatch logs from multiple AWS accounts using Lambda and the AWS SDK

Seeking guidance on querying CloudWatch logs across accounts using lambda and AWS SDK Developing a lambda function in typescript Deploying lambda with CloudFormation, granting necessary roles for reading from two different AWS accounts Initial exe ...

The elixir-typescript compilation process encountered an error and was unable to complete

I am currently working on integrating Angular2 with Laravel 5.2 and facing an issue with configuring gulp to compile typescript files. Below is a snippet from my package.json file: { "private": true, "scripts": { "prod": "gulp --production", ...

You must provide a secret or key in order to use the JwtStrategy

I have encountered the following error and I am unsure of its cause. Can you assist me? ERROR [ExceptionHandler] JwtStrategy requires a secret or key TypeError: JwtStrategy requires a secret or key at new JwtStrategy (C:\Users\wapg2\OneDriv ...

What are the advantages of using any type in TypeScript?

We have a straightforward approach in TypeScript to perform a task: function identity(arg) { return arg; } This function takes a parameter and simply returns it, able to handle any type (integer, string, boolean, and more). Another way to declare thi ...

When attempting to utilize TypeScript with Storybook, Jest may encounter an error stating, "Incompatible types for property 'id'."

Currently, I'm exploring the use of stories in my unit tests with Jest + RTL to reduce redundancy. However, I've encountered an error stating "Types of property 'id' are incompatible" when passing arguments that are also used in my stor ...

Confirm that the string is in the correct JavaScript Date format

I'm encountering an issue with validating the specified string obtained from the new Date() Object. "2020-10-06T14:23:43.964Z". I anticipate receiving either this particular input format or a new Date(). My aim is to create something that ca ...

Guide to integrating dexie with typescript and requirejs

My current project in Typescript involves using requirejs to load jQuery successfully. However, I'm encountering difficulties setting up Dexie. Here is how my require config is set up: require.config({ baseUrl: '', paths: { ...

Utilize TypeScript to access a function from a different module

Currently in the process of migrating a Nodejs project from JavaScript to TypeScript, I encountered an error that was not present when using JavaScript. The issue arises when attempting to access functions defined in a separate module from another module, ...

Is it possible to combine two enums in TypeScript to create a single object with key-value pairs?

Incorporating two enums named Key and Label, as well as an interface called IOption, the goal is to generate an array of objects known as IOptions. const enum Key { Flag = 'flag', Checkbox = 'checkbox', Star = 'star&apo ...

Selenium scraping, Chrome opening is unsuccessful

Currently attempting to gather information from a specific website. The goal is to open a URL using Chromedriver through a designated script. While Chrome opens successfully, it fails to input the desired URL. See the code snippet below: from selenium i ...

Tips on changing the color of a dropdown select option in Angular 8

I have been experimenting with changing the color of a dropdown select menu based on the value selected by the user. Here is the code I have been working with: App.component.ts @Component({ selector: 'my-app', templateUrl: './app.comp ...

I'm looking for ways to incorporate TypeScript definition files (.d.ts) into my AngularJS application without using the reference path. Can anyone provide

I'm interested in leveraging .d.ts files for enhanced intellisense while coding in JavaScript with VScode. Take, for instance, a scenario where I have an Angular JS file called comments.js. Within comments.js, I aim to access the type definitions prov ...

What is the best approach to breaking down attributes upon import according to the theme?

Hey there! Here's the thing - I have this file called <code>colors.ts:</p> export const black = '#0C0C0C'; export const blue = '#22618E'; Whenever I need to use a color, I import it like so: import {black} from 'S ...