Showing posts with label Selenium. Show all posts
Showing posts with label Selenium. Show all posts

Thursday, April 10, 2025

Selenium Java - Warning/Errors and its solutions


Here's a list of standard warnings/errors in Selenium with Java and their respective solutions to help you debug faster and develop cleaner automation scripts.

✅ 1. org.openqa.selenium.NoSuchElementException

Cause: Trying to locate an element that does not exist on the page.

Solutions:

  • Ensure the element is present in the DOM and visible.

  • Add waits:

    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
    
  • Check locator correctness (id, xpath, cssSelector, etc.).


✅ 2. ElementNotInteractableException

Cause: Element is present but cannot be interacted with (e.g., it's hidden or disabled).

Solutions:

  • Use WebDriverWait to ensure it is clickable:

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
    
  • Scroll into view using JavaScript:

    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
    

✅ 3. TimeoutException

Cause: Wait timed out before condition was met.

Solutions:

  • Increase wait time or optimize locator.

  • Use appropriate expected condition (e.g., presenceOfElementLocated vs visibilityOfElementLocated).


✅ 4. StaleElementReferenceException

Cause: WebElement is no longer attached to the DOM.

Solutions:

  • Re-locate the element after page reload or DOM change:

    element = driver.findElement(By.id("elementId"));
    
  • Use a try-catch block to retry locating the element.


✅ 5. SessionNotCreatedException

Cause: Browser version mismatch with WebDriver.

Solutions:

  • Make sure ChromeDriver/GeckoDriver matches your browser version.

  • Use WebDriverManager (for Maven):

    WebDriverManager.chromedriver().setup();
    

✅ 6. WebDriverException: unknown error: DevToolsActivePort file doesn't exist

Cause: Usually in headless mode with Chrome on Linux.

Solutions:

  • Add Chrome options:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--no-sandbox");
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--headless");
    

✅ 7. Deprecation Warnings

Cause: Some older APIs (like Thread.sleep, implicitlyWait without Duration, etc.) are deprecated.

Solutions:

  • Replace deprecated code:

    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    

✅ 8. java.lang.NullPointerException

Cause: WebElement or WebDriver not initialized.

Solutions:

  • Check initialization:

    WebDriver driver = new ChromeDriver(); // Not null
    
  • Ensure correct scope in frameworks like TestNG, JUnit, etc.


✅ 9. org.openqa.selenium.ElementClickInterceptedException

Cause: Another element overlays the clickable element (like a modal or popup).

Solutions:

  • Wait for overlay to disappear.

  • Use JS click:

    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
    

✅ 10. IllegalStateException: The driver executable does not exist

Cause: Path to WebDriver not set correctly.

Solutions:

  • Set system property or use WebDriverManager:

    System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
    

Friday, February 14, 2020

Python with Selenium Webdriver

## Python with Selenium Helper file :-
-----------------------------------------

##Check version/ Is already installed? via CMD
-----------------------------------------------
python --version
pip --version

CTRL + '/' => Comment or Uncomment any line 
CTRL + ALT + SHIFT => Formate Code automatically


##Install Selenium in Python via CMD
---------------------------------------
pip install -U selenium


##Upgrade PIP version via CMD
------------------------------------
python -m pip install --upgrade pip


##Learn Selenium Python : Step by Step
------------------------------------------------------
Step 1 : download python - https://www.python.org/downloads/
Step 2 : Install and check python and pip is installed successfully
              python --version
              pip --version
Step 3 : install selenium libraries
              pip install -U selenium
Step 4 : Download PyCharm - community edition
      https://www.jetbrains.com/pycharm/dow...
Step 5 : Create new project in PyCharm
Step 6 : Adding selenium scripts to the project
   note: those who face problem on click btnK replace it with "q".
Step 7 : Run from IDE
         Run from Command Line


For more deatils about sample project kindly refer a below URL:

https://github.com/autom99/PythonSampleProject/tree/master/PythonWithSelenium


Thursday, January 16, 2020

Python Error solution 100% working

-------------------------------
Error description:
------------------------------
No module found error
any package installation failed  after installing by cmd

Go to PyCharm IDE -> theb
File -> Settings -> Projects -> Select '<Python installation path>' -> then 'Apply'.

then Run again test.

----------------------------------------------

Error messages in Python can often be confusing. Here is a list of common error messages you may find, along with a plain English explanation. These error messages are the result of runtime errors. They will immediately crash your Here are the error messages explained (your error messages may be slightly different but mean the same thing):

SyntaxError: invalid syntax
ImportError: No module named raandom
SyntaxError: EOL while scanning string literal
AttributeError: 'str' object has no attribute 'lowerr'
IndentationError: expected an indented block
IndentationError: unexpected indent
IndentationError: unindent does not match any outer indentation level
TypeError: bad operand type for abs(): 'str'
TypeError: abs() takes exactly one argument (2 given)
IndexError: list index out of range
KeyError: 'spam'
SyntaxError: invalid syntax
This is the most generic error message the Python interpreter will give you. It means that Python was expecting something that isn't there, or there is something there that it didn't expect. Maybe you forgot to include or inserted an extra character. Here are some examples:

if guess = 5:
In the above case, the programmer used = (the assignment operator) instead of == (the equals comparator operator). Python never expects assignment statements where there should be a condition.

def foo(:
In the above case, the programmer forgot to match the ending ) closing parenthesis.

def foo()
In the above case, the programmer forgot to put the colon at the end of the def statement. This can also happen with for, while, if, elif, and else statements.

ImportError: No module named raandom
This error shows up when you try to import a module that does not exist. Most likely, you have a typo in the module name. For example, you may have typed raandom instead of random.

SyntaxError: EOL while scanning string literal
print('Hello world!)
print("Hello world!')
This error happens when you do not have two quote marks for a string, or you use different quote marks for the same string. Look at these two examples:

AttributeError: 'str' object has no attribute 'lowerr'
'Hello'.lowerr()
'Hello'.append('x')
This error appears when you call a method or access an attribute that does not exist. This is most likely because 1) you have a typo in the method or attribute name, or 2) you are calling the method or attribute on a value that is the wrong data type. For example, strings have a method named lower(), but not lowerr() (that is a typo). And the append() method is a list method, so calling it on a string value will cause this error.

IndentationError: expected an indented block
def foo():
print('Hello world!')
This error happens if you fail to indent your code for a block. In the above example the print() call is at the same level of indentation as the def statement, when it should have a larger indentation.

IndentationError: unexpected indent
def foo():
    print('Hello world!')
     print('Goodbye')
An unexpected indent error happens when you add an indentation for no reason. You should only add indentation after a def, if, else, elif, while, or for statment (or any statement that ends with a colon.)

IndentationError: unindent does not match any outer indentation level
def foo():
    print('Hello world!')
   print('Goodbye')
This indentation error appears when you are decreasing the indentation, but not decreasing it to the same level as the previous indentation. The print('Goodbye') call should either be at the same indentation as the other print() call (and be inside the if block) or at the same indentation as the if statement (and be outside of the if block).

TypeError: bad operand type for abs(): 'str'
abs('Hello')
This error occurs when the value of an argument you pass to a function or method is of the wrong data type. In the above example, the abs() function takes an integer or floating point number. Passing a string for the argument results in an error.

TypeError: abs() takes exactly one argument (2 given)
abs(42, 50)
This error appears when you pass the wrong number of arguments to a function or method, either too many or too few. The abs() function takes exactly one (and only one) argument. In our example we pass two arguments, which results in this error.

IndexError: list index out of range
myList = ['spam', 'fizz', 'eggs']
print(myList[3])
The IndexError happens when the index you use is larger than or equal to the number of actual items in the list. In our above example, the myList list only has 3 items in it, so the only valid indexes to use are 0, 1, and 2. The index 3 (or any other index larger than 2) is larger than any of these indexes, so the code results in an IndexError.

KeyError: 'spam'
myDict = {'fizz':42, 'eggs':100}
myDict['spam']
The KeyError happens when you try to access a key in a dictionary object that does not exist. Either the key was never added to the dictionary, was deleted previously with the del operator, or the key you are using has a typo in it.


------------------------------------------------------------
Some Useful URL for error solving in Python
--------------------------------------------------------------

http://inventwithpython.com/appendixd.html

https://nostarch.com/automatestuffresources

https://nostarch.com/automatestuff2

https://pyautogui.readthedocs.io/en/latest/install.html



Python with Selenium Helper file

## Python with Selenium Helper file :-
-----------------------------------------

##Check version/ Is already installed? via CMD
-----------------------------------------------
python --version
pip --version

CTRL + '/' => Comment or Uncomment any line
CTRL + ALT + SHIFT => Formate Code automatically


##Install Selenium in Python via CMD
---------------------------------------
pip install -U selenium


##Upgrade PIP version via CMD
------------------------------------
python -m pip install --upgrade pip


##Learn Selenium Python in ONE VIDEO | Step by Step
------------------------------------------------------
Step 1 : download python - https://www.python.org/downloads/
Step 2 : Install and check python and pip is installed successfully
              python --version
              pip --version
Step 3 : install selenium libraries
              pip install -U selenium
Step 4 : Download PyCharm - community edition
      https://www.jetbrains.com/pycharm/dow...
Step 5 : Create new project in PyCharm
Step 6 : Adding selenium scripts to the project
note: those who face problem on click btnK replace it with "q".
Step 7 : Run from IDE
         Run from Command Line

Maven installation guide for beginner

## Maven installation guide :-
--------------------------------

Step -1
--------
Download Binary files for MAVEN from below url:

https://maven.apache.org/download.cgi

Step -2
--------
Go to Eclispe -> Help -> Install New Software -> Click on 'Add' button then enter:

Name: M2Eclipse
URL: http://download.eclipse.org/technology/m2e/releases/1.3

Then,Waiting for finishing download and installation of MAVEN into your Eclispe.


Step -3
--------
Checked on 'Maven Integration for Eclispe' then Click on 'Next'.
Then,Waiting for finishing setup automatically by Eclispe.

Friday, October 4, 2019

XPath and CSS finder Chrome Extension Tool: Eskry

Eskry

Eskry is a free browser add-on/extension that helps automation testers and developers generating locators for HTML elements. 

From Chrome Web store find this tool and add to Chrome as plugin


For more details open above URL and type "ESKRY" in search box as followed by image:


After successfully adding this plugin,check for icon as illustrated in below image.


Then for testing purpose open a below URL in browser


After open url in chrome browser press F12 or Ctrl + Shift + I as Inspect element then look for a "Eskry " tab as illustrated in below image



Checkout below image for click on Title of the website and title of Register form 


Click on TEST button then it will be highlighted on screen as illustrated below


And then you can use for Automation Script for locator any specific elements in a browser.

Thank you very much for a reading this blog.