Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"InvalidElementStateException: Message: invalid element state" error showing for "Input Text //*[@id="search"] never" command #1838

Closed
tvigneshnayak opened this issue Jun 13, 2023 · 5 comments

Comments

@tvigneshnayak
Copy link

System Conditions :
Browser: Google Chrome Version 114.0.5735.110 (Official Build) (64-bit)
Browser driver: Chrome WebDriver version: 114.0.5735.90
Operating System: Windows 11 Pro
I am using selenium 4.9.0 and Robot Framework 6.1 (Python 3.11.3 on win32 )

Steps followed :
I am trying to execute simple testcase but it is throwing error for "Input Text //*[@id="search"] never" command, I have pasted my script below. Please check. I am using Xpath as selector.

*** Settings ***
Library SeleniumLibrary

*** Test Cases ***
Sample Test Case for verifying the basic functionality
[Documentation] Test case documentation
Open Browser https://www.youtube.com chrome
Maximize Browser Window
Input Text //*[@id="search"] never
Press Keys //*[@id="search-icon-legacy"]/yt-icon/yt-icon-shape/icon-shape/div [RETURN]
# Add more test steps if needed
Page Should Contain never
Sleep 5s
Close Browser

*** Keywords ***

Expected Output : It should input the text in the search option of YouTube.

I have attached log file. I have used other website's search box, it is working properly( if you change the selector but for YouTube it is showing error. Please let me know if any additional details is needed. I appreciate any help.
log.pdf

@emanlove
Copy link
Member

emanlove commented Jun 13, 2023

You mentioned in the other thread

Input Text //*[@id="search"] never ---- this step is not executing, it is showing InvalidElementStateException

Selenium's error messages are very telling in that they point towards the issue. InvalidElementStateException means "the element is in an invalid state" [reference] which for a input text keyword this generally means it is disabled. As you just opened the browser and navigated to the site I suspect you just need to wait for the input to be enabled. A quick check would be to temporarily add a sleep before inputting the text. If that works then you should consider your waiting strategy for the application under test to be "ready" before proceeding.

@tvigneshnayak
Copy link
Author

Hi thanks for replying. I have added two extra lines but it is still showing same error.
*** Test Cases ***
Sample Test Case for verifying the basic functionality
[Documentation] Test case documentation
Open Browser https://www.youtube.com chrome
Maximize Browser Window
Sleep 5s
Element Should Be Enabled //*[@id="search"]

Input Text //[@id="search"] never
Press Keys //
[@id="search-icon-legacy"]/yt-icon/yt-icon-shape/icon-shape/div [RETURN]
# Add more test steps if needed
Page Should Contain never
Sleep 5s
Close Browser

I have attached the log file. Element Should Be Enabled //[@id="search"] this step is passed but Input Text //[@id="search"] never this step is failed, how is this possible?
log.pdf

@emanlove
Copy link
Member

Checking that xpath on https://www.youtube.comshows that xpath matches five elements, assuming youtube is render the same for you and me.
image
As such it will grab the first one which is a <g> or a svg element. Instead you want the input element so you might try //input[@id="search"] instead.

@tvigneshnayak
Copy link
Author

@emanlove thanks a lot, it is working properly.

@sowjiterralogicc
Copy link

Hi,
This is my code for flight booking automation.
Settings
Library SeleniumLibrary

*** Test Cases ***
Testsocialmedia
Open Browser https://www.expedia.com/ chrome
Maximize Browser Window
sleep 5s
Click Element xpath://a//span[text()='Flights']
sleep 2s
Click Element xpath://a//span[text()='One-way']
sleep 10s
Wait Until Element Is Visible xpath://div[@Class="uitk-field has-floatedLabel-label has-icon"]/button[@aria-label="Leaving from"] timeout=20s
Input Text xpath://div[@Class="uitk-field has-floatedLabel-label has-icon"]/button[@aria-label="Leaving from"] Bangaluru
sleep 5s

I am getting error like this
Flight Booking

Testsocialmedia
DevTools listening on ws://127.0.0.1:58600/devtools/browser/0ae616ee-a325-44e9-8add-334043cfea9f
Testsocialmedia | FAIL |
InvalidElementStateException: Message: invalid element state
(Session info: chrome=117.0.5938.132)
Stacktrace:
GetHandleVerifier [0x00007FF76AC07D12+55474]
(No symbol) [0x00007FF76AB777C2]
(No symbol) [0x00007FF76AA2DF9D]
(No symbol) [0x00007FF76AA6732A]
(No symbol) [0x00007FF76AA8F15A]
(No symbol) [0x00007FF76AA656E6]
(No symbol) [0x00007FF76AA8F370]
(No symbol) [0x00007FF76AAA7EF2]
(No symbol) [0x00007FF76AA8EF33]
(No symbol) [0x00007FF76AA63D41]
(No symbol) [0x00007FF76AA64F84]
GetHandleVerifier [0x00007FF76AF6B762+3609346]
GetHandleVerifier [0x00007FF76AFC1A80+3962400]
GetHandleVerifier [0x00007FF76AFB9F0F+3930799]
GetHandleVerifier [0x00007FF76ACA3CA6+694342]
(No symbol) [0x00007FF76AB82218]
(No symbol) [0x00007FF76AB7E484]
(No symbol) [0x00007FF76AB7E5B2]
(No symbol) [0x00007FF76AB6EE13]
BaseThreadInitThunk [0x00007FF8E58E257D+29]
RtlUserThreadStart [0x00007FF8E714AA68+40]

Flight Booking | FAIL |
1 test, 0 passed, 1 failed

can u solve this issue if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants