
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I get Webdriver Session ID in Selenium?
We can get the webdriver session id with Selenium webdriver using the SessionId class. A session id is a distinctive number that is given to the webdriver by the server.
This number is utilized by the webdriver to establish communication with the browser. The commands in our Selenium tests are directed to the browser with the help of this session id. The method getSessionId is used to obtain the webdriver session id.
Syntax
SessionId s = ((RemoteWebDriver) driver).getSessionId();
Example
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.remote.RemoteWebDriver; public class BrwSessionId{ public static void main(String[] args) { //set chromedriver.exe file path System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/index.htm"); //get webdriver session id SessionId s = ((RemoteWebDriver) driver).getSessionId(); System.out.println("Session Id is: " + s); //browser close driver.quit(); } }
Output
- Related Questions & Answers
- How to do session handling in Selenium Webdriver?
- How do I set the Selenium webdriver get timeout?
- How can I handle multiple keyboard keys using Selenium Webdriver?
- How do I get current URL in Selenium Webdriver 2 Python?
- How can I scroll a web page using selenium webdriver in python?
- How do I open Chrome in selenium WebDriver?
- How can I close a specific window using Selenium WebDriver with Java?
- How can I select date from a datepicker div using Selenium Webdriver?
- How can I download Microsoft WebDriver/Edge Driver to use with Selenium?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- What can selenium WebDriver do?
- How to get Tooltip Text in Selenium Webdriver?
- How do I get a parent HTML Tag with Selenium WebDriver using Java?
- How do I resolve the ElementNotInteractableException in Selenium WebDriver?
Advertisements