Selenium 4 Beginner Tutorial 1 | Introduction, Setup & Browser Actions | Step by Step
HTML-код
- Опубликовано: 1 авг 2024
- All FREE courses - automationstepbystep.com/
Selenium Quiz - automationstepbystep.com/quiz...
GitHub - github.com/Raghav-Pal/Seleniu...
00:00 Introduction
01:35 Selenium 4
03:48 Getting Started - Project Setup
09:31 1st Test
19:30 WebDriverManager
24:33 Browser Actions
25:25 How to open a web page
26:23 Get current URL
27:00 Get Title
27:53 Forward | Back | Refresh
29:44 Switching windows
32:12 Open new Window
33:26 Open new Tab
36:58 Close Browser
38:00 Frames
44:20 Get & Set Window size
48:49 Get & Set Window position
51:44 Maximize | Minimize | Full Screen
53:06 Screenshot
59:04 JavaScript Executor
01:03:58 Conclusion
Selenium 4
--------------
New and improved version of Selenium
Se webdriver can directly communicate with browser using W3C protocol
(without use of json wire protocol as earlier)
New functions added
Multiple windows & tabs management
Relative locators
New Documentation
Getting Started
-------------------
Install Java
Setup Eclipse
Create a new maven project
Add maven dependencies for Selenium 4
Download browser driver & add in a folder in project
(Can also keep at any location on your system and add the location in path env var)
Optional
Add TestNG plugin
Add TestNG dependency
1st Test
---------
Step 1 - Create a class & main method
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
//timeout driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.manage().timeouts().scriptTimeout(Duration.ofMinutes(2)); driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
//close
driver.close();
}
Step 2 - Run code
Using WebDriver Manager
Step 1 - Add maven dependency for webdriver manager -
bonigarcia.dev/webdrivermanager/
Step 2 - Add code
WebDriverManager.chromedriver().setup();
Step 3 - To use specific ver of browser
WebDriverManager.chromedriver().driverVersion("92.0").setup();
Browser Actions
----------------------
1. Open a web page
driver.get("google.com");
driver.navigate().to("selenium.dev");
2. Get current url
driver.getCurrentUrl();
3. Get title
driver.getTitle();
4. Forward | Back | Refresh
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
5. Switching windows
String originalWindow = driver.getWindowHandle();
driver.switchTo().window(originalWindow);
6. Open new window and switch to the window
driver.switchTo().newWindow(WindowType.WINDOW);
7. Open new tab and switch to the tab
driver.switchTo().newWindow(WindowType.TAB);
8. Closing browser
driver.close();
driver.quit();
9. Frames
Locate and Switch
WebElement iframe = driver.findElement(By.cssSelector(".rightContainer>frame"));
driver.switchTo().frame(iframe);
Using id or name
driver.switchTo().frame("classFrame");
Using index
driver.switchTo().frame(1);
Return to top level window
driver.switchTo().defaultContent();
10. Window management - Size
Get width & height
int width = driver.manage().window().getSize().getWidth();
int height = driver.manage().window().getSize().getHeight();
Store dimensions & query later
Dimension size = driver.manage().window().getSize();
int width1 = size.getWidth();
int height1 = size.getHeight();
Set window size
driver.manage().window().setSize(new Dimension(800, 600));
10. Window management - Position
Access x and y dimensions individually
int x = driver.manage().window().getPosition().getX();
int y = driver.manage().window().getPosition().getY();
Store dimensions & query later
Point position = driver.manage().window().getPosition();
int x1 = position.getX();
int y1 = position.getY();
Move the window to the top left of the primary monitor
driver.manage().window().setPosition(new Point(0, 0));
10. Window management
// maximize window
driver.manage().window().maximize();
// minimize window
driver.manage().window().minimize();
// fullscreen
driver.manage().window().fullscreen();
11. Screenshots
Take screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("./image.png"));
Take element screenshot
WebElement element = driver.findElement(By.cssSelector(".lnXdpd"));
File scrFile1 = element.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile1, new File("./image1.png"));
12. JavaScript
Create JavascriptExecutor interface object by Type casting
JavascriptExecutor js = (JavascriptExecutor)driver;
Get return value from script
WebElement button =driver.findElement(By.name("btnI"));
String text = (String) js.executeScript("return arguments[0].innerText", button);
JavaScript to click element
js.executeScript("arguments[0].click();", button);
Execute JS directly
js.executeScript("console.log('hello world')");
#Selenium4Tutorials
If my work has helped you, consider helping any animal near you, in any way you can.
Never Stop Learning
Raghav
What’s New in Selenium 4
* Selenium is now W3C compliant
* Relative Locators
* Better Window/Tab Management
* Improved Selenium Grid
* Upgraded Selenium IDE
* New APIs for CDP (Chrome DevTools Protocol)
* Deprecation of Desired Capabilities
* Modifications in the Actions Class
Hello sir, can you please suggest some tutorial for java based robot framework. Pleas
Great video! I watched all your new Selenium 4 videos, as well as your older videos since learning from them 2 years back. I forgot if your new videos mentioned this so I would like to share this info if anyone else ran into my problem. Upgrading from Selenium alpha-4.0 to the latest 4.0 (as of 11/23/2021) I had to also download the latest geckodriver (for FireFox). Otherwise nothing would work. Hope this helps anyone having upgrade issues.
The
You rock, thanks so much! this was very helpful and well organized, you're a great teacher!
You are so welcome! K K
Thank you a lot! I cannot even explain how much you are helping me with my selenium class. My university professor doesn't even explain this clear. 💜
So happy to know this is helping Tasha
Yes cls was amazing
I can not express my gratitude for you..i am totally beginner but with help of your youtube video i learnt lot today. Thanks a lot
Glad to hear that
Great video Raghav! Another Gem. My confidence is high again- exactly the review I needed. You are a 🤖 (Machine).
Glad it was helpful Benjamin
Hi Raghav, I recently join your channel and found your selenium series is very useful for all who are looking forward in automation or experienced in Automation. Kindly do post videos as sequence so we can impove our skill by your helping videoes.
Sure will do Shivam
Thank you so much for this session, please carry on.
Thank you, I will Ankit
Your tech teaching style is really effective. I'm learning so much
Awesome, thank you Varun
Very helpful tutorial. Keep up the good work. ✨😀💖
Thank you so much 🤗
By far very good selenium video , Thanks for your explanation.
Most welcome
Thanks for the video. Did not see any notable change in script compared selenium 3. Eagerly waiting for the next part.
I will highlight the changes, next part (coming Thu) will have Relative Locators, that is an imp change in Selenium 4
Awesome tutorial; very easy way to learn; thanks a lot
You are welcome!
i love you for who that make this video, it's very very helpfull for me. So amazing !!
Most welcome
Thank you Raghav bro, it really helpful
Most welcome Prasad
Woooow amazing video really useful thanks!!!
Most welcome
He never disappoints.... thank you again sir
Most welcome Mzamo
You are e legend. Making me look good in my job
Really superb video lots thanks to you for explanation sharing Knowledge really awesome
So nice of you
Very helpful video and it really helped me move forward by doing a Maven project and adding dependencies than a Java project initially. I like the step by step explanations. Thank you so much Raghav!
You're very welcome Rashmi
@@RaghavPal Can you create a TestNG video for Selenium 4 please? It will be very helpful.
I will check and plan
very well done 👌👏👏 thank you!
Most welcome
Super bro ur videos r helping me alot...Thank u very much
Most welcome Krishna
Appreciate you Raghav.
Thanks Aydin
There were a lot of changes in the Actions class - Interaction API, hope you will cover them in the 2nd part ❤️
I will plan all this Prasanth
thank u a lot for the great tutorial!
You're very welcome Ekaterina
Great video and practice thank you for actuallity code in selenium 4 .
Most welcome Cristian
@@RaghavPal Thank you.
Thank you for the video..!! 👏👏👏👏👏
Most welcome Suyama
Thanks a lot. Very good explanation.
You are welcome Padma
Thanks for narrowing basic Selenium4 session
Most welcome
Thanks Raghav 👍
Most welcome
Thanks a lot.
Most welcome Aydin
Very good beginning
...
Thanks Sudhakara
Hi Raghav, waiting for second part
Coming today :)
Really we should Thank u @Raghav
Most welcome
Legend
Hi raghav! I came across ur channel and found it soo much interesting. It's been 1 year of my working as an Analyst (QA) at Deloitte (Salesforce Tech currently) and now I desire to learn Automation part. So can I follow this end to end tutorial! I feel i am on right path🙌🏻✨
Are there any changes too which I need to be updated with??
Yes, can start on it Shavez, you will get more tutorials here - automationstepbystep.com/
Ur great sir....
Thanks a lot Akash
thank you sir..
Most welcome Bhavesh
39:24 Hi Raghav, the iFrames are obsolete since HTML5 right? What has replaced them? DIVs? Do we usually use DIVs then to locate specific elements?
Syed
iFrames are not obsolete in HTML5. They are still a valid way to embed one web document inside another. However, they are not used as often as they used to be, because there are other ways to embed content, such as using DIVs and CSS.
DIVs are HTML elements that can be used to create containers for other elements. They can be used to position and style elements on a page. DIVs can also be used to encapsulate content, such as ads or embeds.
To locate specific elements within a DIV, you can use the same CSS selectors that you would use to locate elements on the main page. For example, to locate all of the `` elements within a DIV with the ID `my-div`, you would use the following CSS selector:
```
#my-div h1
```
You can also use JavaScript to locate and interact with elements within a DIV.
**Whether you should use a DIV or an to locate specific elements using Selenium depends on the structure of the web page.** If the element you are trying to locate is inside an , then you will need to switch to the before you can locate the element. To do this, you can use the `switchTo()` method.
Here is an example of how to switch to an using Selenium Java:
```java
WebDriver driver = new ChromeDriver();
// Switch to the
driver.switchTo().frame("my-");
// Locate the element within the
WebElement element = driver.findElement(By.cssSelector("h1"));
// Do something with the element
element.click();
```
**If the element you are trying to locate is not inside an , then you can use the same CSS selectors that you would use to locate elements on the main page.**
Here is an example of how to locate an element on the main page using Selenium Java:
```java
WebDriver driver = new ChromeDriver();
// Locate the element on the main page
WebElement element = driver.findElement(By.cssSelector("h1"));
// Do something with the element
element.click();
```
Overall, the best way to locate specific elements using Selenium is to use the CSS selectors that are appropriate for the structure of the web page
excellent
Many thanks Sonal
Hi Raghav Sir, I am a new tester and want to learn selenium for automation testing using Java . So is the selenium 4 playlist enough or are they any pre requisite I need to watch on the channel before I start watching selenium 4 playlist . Will wait for the reply thank you.
Hi, this playlist will be good for you, can also check my selenium java framework here automationstepbystep.com/
Hi Sir, your video explained well. have one doubt. if username/password -the class name is the same and id is dynamic because each time refreshed. how can I write a script for this scenario? @Automation Step by Step
Hi Yuvaraj, usually the id is unique but in your case if class name is consistent and can be used to locate the element, you can use that
Hi Raghab, your tutorials are great, I am learning a lot from your tutorial..but in this video @ 31:34 the command did not actually work..also I have tried this in my IDE, it's not switching to the originalWindow..can you please help me solve this problem?..
Hi Zahid, pls check your commands, code and syntax again, can also try some more online examples and try
Hi Raghav, thanks a lot for the videos. I have one quick question, even when I follow all the steps and add dependencies in pom.xml file, Maven doesn't download the dependencies. I tried to fix the issue but didn't get any help in the interent. I am using my personal laptop and my home internet. settings.xml file needs proxy details which I don't have.
Hi, there are several options you can try. Check this
stackoverflow.com/questions/26506364/maven-not-downloading-new-added-dependency-in-pom-xml-file
Thanks for your explanation. Can we expect videos Selenium with C# ?
Yes, I will do
Instead of using webdriver can i use chrome driver... Is it enough!?. When i import webdrivermanager(5.1.1) that is not added in the maven repository
you can try
Hi, I hve created maven project and added dependency into Pom file,but when I save it I am not able to see maven dependencies folder at left side,please hell
Hi Mubeena, Right-click on the project and choose Properties, and then Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects" Hit Apply, and then OK. Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies)
Hi I am having this error when trying to create a maven project, how can i get this resolved
I am on windows 10 64 bit and am using Eclipse 2021-09
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6
Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6
Multiple annotations found at this line:
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be
resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: org.apache.maven.plugins:maven-
compiler-plugin:pom:3.1 failed to transfer from repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and
resolution is not reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact
org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 from/to central (repo.maven.apache.org/maven2): repo.maven.apache.org
- org.apache.maven.plugins:maven-resources-plugin:pom:2.6 failed to transfer from repo.maven.apache.org/maven2 during a previous attempt. This
failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced. Original error: Could
not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (repo.maven.apache.org/maven2): repo.maven.apache.org
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile,
phase: test-compile)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase:
compile)
Pls check this stackoverflow.com/questions/12533885/could-not-calculate-build-plan-plugin-org-apache-maven-pluginsmaven-resources
While creating maven project,an error occurs "could not calculate build plan: plugin".please tell me a solution
Hi Vishnu, pls see if any options here can help
stackoverflow.com/questions/21909466/could-not-calculate-build-plan-plugin-org-apache-maven-pluginsmaven-jar-plugin
Hello Raghav,
when I run the test without downloading the driver or adding the WebdriverManager it still works! Is this something new from the latest update? Or should I still add the WebdriverManager?
Hi Sabine, it may be possible that the path to your chromedriver.exe is set in your env PATH variable and is accessible from anywhere on your system
Wonderful! Can you please tell how can i create default profile, so my qr login informations can store?
Hi Ali, do you mean profile on browser like chrome. you can use chrome options. www.edureka.co/community/80815/how-to-open-chrome-default-profile-with-selenium
Hello Raghav - I have recently subscribed to your channel as i found the Videos around SE very intresting. I do not know why i am not able to see all videos here in this list?
It says 9 videos are hidden. Any help around it?
Welcome aboard Sadique, they are in process and will be published soon. Mostly you will get one video each week until all are published
is there a video on automated log in for selenium java I'm really struggling as the website i'm using does not have a defined id so need to use class or xpath?
Emma
Here's a guide to automating login using Selenium Java without ID attributes, focusing on class and XPath selectors:
1. Inspect Elements:
- Use browser developer tools (usually by pressing F12) to examine the login page's HTML structure.
- Identify the elements you need to interact with (username field, password field, login button).
- Note their class names, XPath expressions, or other identifying attributes.
2. Import Necessary Classes:
```java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
```
3. Locate Elements Using Class:
```java
// Example using class name:
WebElement usernameField = driver.findElement(By.className("username-input"));
WebElement passwordField = driver.findElement(By.className("password-field"));
WebElement loginButton = driver.findElement(By.className("login-btn"));
```
4. Locate Elements Using XPath:
```java
// Example using XPath:
WebElement usernameField = driver.findElement(By.xpath("//input[@class='username-input']"));
// Combine multiple attributes for specificity:
WebElement passwordField = driver.findElement(By.xpath("//input[@type='password'][@class='password-field']"));
```
5. Interact with Elements:
```java
usernameField.sendKeys("your_username");
passwordField.sendKeys("your_password");
loginButton.click();
```
6. Wait for Login Completion (Optional):
- If necessary, add explicit waits to ensure the login process finishes before proceeding:
```java
WebDriverWait wait = new WebDriverWait(driver, 10); // Wait up to 10 seconds
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[text()='Welcome']")));
```
Additional Tips:
- Uniqueness: Ensure selectors are unique to target the correct elements.
- Dynamic Elements: Handle dynamic elements that load after page rendering using explicit waits.
- Error Handling: Implement try-catch blocks to manage potential exceptions.
- Best Practices: Follow Selenium best practices for clean and maintainable code.
By following these steps and tips, you can effectively automate login scenarios even without ID attributes, ensuring your Selenium Java tests are adaptable and reliable.
its asome
Thanks
Hello Raghav.. thanks much for such wonderful n knowledgeable videos. One QQ is there a way to create a short cut of JMeter over desktop MAC . So that user simple click the icon n JMeter open
Yes, you can add a .bat file with the commands
@@RaghavPal thanks much Raghav for the response really appreciate.. request you to please elaborate on the same what command to be passed with .bat file
basically, you will need to copy all the commands that you use to start JMeter in a text file and then convert into a bat. For mac it can be .sh file, Can check this codeburst.io/how-to-create-shortcut-commands-in-the-terminal-for-your-mac-9e016e25e4d7
www.switchingtomac.com/tutorials/how-to-run-a-terminal-command-using-a-keyboard-shortcut-on-mac/
I'm having "launch error" upon execution, how do I fix it? thanks
What is the error, can try online help too
Thank you for this great work
You're very welcome Younes
Can I start learning Selenium with this playlist or I have to complete Your Previous Selenium Videos first?
Yes, you can Mansi, in case you need some basic Selenium overview, can check some Selenium Beginners playlist here - automationstepbystep.com/
Hi Raghav in interviews they are asking for solving complex java programs like leered code please help with coding.
Hi, learning some concepts will always help, as per my exp, not all org check for deep programming knowledge for automation
Hi sir, You are wonderful
I have a question >I'm unable to open the Empty browser >I'm getting an Exception like this >" Exception in thread "main" java.lang.AssertionError: No System TLS "> please help me with this sir.
Hi Santhosha, looks like you missed some settings or imports, Pls check groups.google.com/g/j2objc-discuss/c/wuQnmz2xftA?pli=1
Hi Raghav,I have a scenario where in user clicks on download button in UI for a particular module and sub-module then an outlook mail is triggered. I need a code where i would pass the module name and sub-module name as argument to vba code and use the same to validate that email is received in ms-outlook and in some scenarios read the email and if any attachments are there download the same.
Hi, do not have a code for this, can try online resources
@@RaghavPal I have the vba code to download the msg file. But how to pass the arguments from java selenium to Subroutine.ex:Sub readMail() //code End Sub and keep invoking this for a particular duration,l ike check the mail every 5mins for a maximum of 30mins.
not very sure on this, will need to check online
Sir, I didnt include chrome driver path nor did i include webdriver manager setup but somehow my code worked and browser was launched. What can be reason for it ?
Most probably you might have the path of chrome driver set in your path env variables
@@RaghavPal Thank you sir 😊
Hi raghu..this is normal java application or spring boot application? if it is a springboot application why u create main method in test class?
It is normal java here
Thanks Raghav, lovely content.
Where does this term WebDriver comes in line
WebDriver Driver = new ChromeDriver();
Is it a key Term, like when we are declaring a variable or something?
Ok, I got it I think. We have to import the functionality or package, to tell Java which browser to use. Thank you
Great, all the best Syed
Hello,
I am getting error "Cannot invoke "Object.toString()" because the return value of "java.util.Map.get(Object)" is null" before opening the google browser ? Any suggesstions how to fix this ??
Hi Deepthi
The error message "Cannot invoke 'Object.toString()' because the return value of 'java.util.Map.get(Object)' is null" suggests that you are trying to access a value from a `Map` object, but the key you are using does not exist in the map, resulting in a `null` value.
To fix this issue, you should check the key you are using to access the value and ensure that it exists in the map. Here are a few suggestions to resolve the problem:
1. Verify the key: Double-check the key you are using to retrieve the value from the map. Make sure it matches the key that was used to store the value in the map.
2. Check the map initialization: Ensure that the map is properly initialized and populated with the expected key-value pairs before accessing any values from it. If the map is empty or does not contain the desired key, you will encounter a `null` value.
3. Handle null values: If it is expected that the map may contain `null` values for some keys, add null-checking logic before invoking `toString()` on the retrieved value. You can use an `if` statement to check if the value is `null` and handle it accordingly.
Here's an example of how you can handle null values:
Map map = ...; // your map object
String key = ...; // the key you want to access
Object value = map.get(key);
if (value != null) {
String valueString = value.toString();
// Use the valueString or perform further operations
} else {
// Handle the case when the value is null
}
By verifying the key, checking the map initialization, and handling null values appropriately, you should be able to resolve the error and access the desired values from the map without encountering a `null` value
@@RaghavPal Very descriptive explaination, thank you!! As I don't know Java, this seems quite hard to understand. I have typed exactly same code in Eclipse IDE as shown in your video and I tried to open the Google website.
Got this error. I got stuck with this error and couldn't move to the next step.
will need to check in detail. Can try some online help meanwhile
Sir not getting option to import
When hover on
Webdriver driver =new Chrome Driver();
Path is also set for chrome driver however
Check some examples based on the version of selenium you are using
Sir
I would like to do as freelancer in software testing as fresher.
I know selenium how to write code but how to rise issues and submit
Tirumala
can study some defect management tools online
Hi Raghav!I have a basic, silly doubt..not clear about" what is selenium " bcoz coding is done java, or they use testng. So can functional testing b done with just Java( or testng) without selenium
Hi Urmila, Selenium is a library that has classes and functions created to interact with the browser. So when you import Selenium libraries, you get access to use these functions in your code, Now Selenium provide the libraries in multiple programming languages like Java, Python, C#, Ruby, JS etc
So you can choose as per your needs and requirements
in this current course u will repeat all concepts or only the updates in latest version of selenium
Hi Saim, I will focus more on Selenium 4 new features, but I have to go with all the setup and steps so that even a new beginner can follow
Google chrome cannot read write data to its data directory - im getting this error pls help to resolve
Hi Vanaja
The error "Google Chrome cannot read and write data to its data directory" occurs when Chrome does not have permission to write to its data directory. This can happen for a few reasons, such as:
* The data directory is not writable.
* The user does not have permission to write to the data directory.
* The data directory is full.
To resolve the error, you need to make sure that the data directory is writable and that the user has permission to write to it. You can also try deleting the data directory and then restarting Chrome.
Here are some steps you can take to resolve the error:
1. Check the permissions on the data directory. You can do this by opening the Windows Explorer and navigating to the data directory. Right-click on the data directory and select "Properties". In the "Permissions" tab, make sure that the user has "Full Control" permission.
2. If the data directory is full, you can try deleting it and then restarting Chrome.
3. If you are still getting the error, you can try reinstalling Chrome.
Here are the steps to create a writable data directory for Chrome:
1. Open the Windows Explorer and navigate to the `C:\Users\\AppData\Local\Google\Chrome\User Data` directory.
2. Create a new directory called `Default`.
3. Give the `Default` directory full control permissions.
Once you have created a writable data directory, you should be able to run Chrome without getting the error.
hope this helps
Hello, I know this video came out about a year ago but I was getting this error message that states that Eclipse did not have authorization to do things to open the web browser properly and close it. After a quick search, I found out that after Chrome v102 security permissions were implemented that prevent these other programs from just opening Chrome. Turns out you need to add:
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
WebDriver driver = new ChromeDriver(options);
To make the webpage open and close properly. I still get warnings though but hey, it works.
Hi Selmir
That's correct. Chrome v102 introduced new security permissions that prevent programs from opening Chrome without permission. The `-remote-allow-origins=*` argument tells Chrome to allow any origin to open it. This is necessary for Selenium to be able to control Chrome.
The warnings you are seeing are probably due to the fact that you are using a non-standard configuration for Chrome. These warnings can be safely ignored.
Here is a more detailed explanation of what is happening:
* When you start Chrome, it checks to see if it has been granted permission to be opened by other programs. If it has not, it will display an error message and refuse to open.
* The `-remote-allow-origins=*` argument tells Chrome to allow any origin to open it. This means that Selenium will be able to open Chrome even if it does not have permission to do so.
* The warnings you are seeing are due to the fact that you are using a non-standard configuration for Chrome. These warnings can be safely ignored.
I hope this helps
what selenium version are companies expecting for in interviews? 3 or 4?
4 is more recent, many organizations still use Se 3. If you have not done earlier, go with 4
hi!
11:18 I am not getting any suggestions when I hover over WebDriver
I use Mac. Is it okay?
Syed, that's okay, as far as it is functional
@@RaghavPal thanks Raghav; I fixed it by going in Preferences > Java > Content.... etc.
Hi Raghav, I'm trying the selenium 4.7.2 with 107 devtools version, but I see some issue.. Is there any way that I can contact you. Kindly help on this.
Hi, you can send me the details here
@@RaghavPal Hi, I want to fetch the Payload tab from F12, apart from headers.
will need more details and context here, is this related to any specific part of this videos, If yes, pls send the timestamp
Hi sir , i am not getting import WebDriver option on hovering, other options like create class are coming but not import one, pls help
Hi Adnan
If you are not seeing the "import WebDriver" option when hovering over the WebDriver class in Eclipse, it may indicate that the Selenium WebDriver library is not properly configured in your project. Here are a few steps you can take to resolve the issue:
1. Ensure that you have added the Selenium WebDriver library to your project's build path. To do this, right-click on your project in the Project Explorer, go to "Build Path," and select "Configure Build Path." In the Libraries tab, click on "Add External JARs" or "Add JARs" and navigate to the location where you have the Selenium WebDriver JAR file(s) saved. Select the JAR file(s) and click "Apply" or "OK" to add them to your project
2. Check if the WebDriver JAR files are present in your project's referenced libraries. Expand the "Referenced Libraries" folder in your project and ensure that you see the Selenium WebDriver JAR files listed there. If they are missing, you may need to add them as mentioned in step 1
3. Make sure that the Selenium WebDriver import statement is correctly written in your Java file. The import statement should be as follows:
```java
import org.openqa.selenium.WebDriver;
```
If you are trying to import a specific WebDriver implementation, such as ChromeDriver or FirefoxDriver, you should use the appropriate import statement for that specific class
4. Try refreshing your project. Right-click on your project in the Project Explorer and select "Refresh" to reload the project's resources and dependencies
5. If the issue persists, try restarting Eclipse to ensure that any potential configuration errors are cleared
By following these steps, you should be able to properly import the WebDriver class and use it in your Selenium Java project
Hi Adnan
If you are not seeing the "import WebDriver" option when hovering over the WebDriver class in Eclipse, it may indicate that the Selenium WebDriver library is not properly configured in your project. Here are a few steps you can take to resolve the issue:
1. Ensure that you have added the Selenium WebDriver library to your project's build path. To do this, right-click on your project in the Project Explorer, go to "Build Path," and select "Configure Build Path." In the Libraries tab, click on "Add External JARs" or "Add JARs" and navigate to the location where you have the Selenium WebDriver JAR file(s) saved. Select the JAR file(s) and click "Apply" or "OK" to add them to your project.
2. Check if the WebDriver JAR files are present in your project's referenced libraries. Expand the "Referenced Libraries" folder in your project and ensure that you see the Selenium WebDriver JAR files listed there. If they are missing, you may need to add them as mentioned in step 1.
3. Make sure that the Selenium WebDriver import statement is correctly written in your Java file. The import statement should be as follows:
```java
import org.openqa.selenium.WebDriver;
```
If you are trying to import a specific WebDriver implementation, such as ChromeDriver or FirefoxDriver, you should use the appropriate import statement for that specific class.
4. Try refreshing your project. Right-click on your project in the Project Explorer and select "Refresh" to reload the project's resources and dependencies
5. If the issue persists, try restarting Eclipse to ensure that any potential configuration errors are cleared
By following these steps, you should be able to properly import the WebDriver class and use it in your Selenium Java project
Hello, Raghav! Thanks a lot for the tutorials! It's very helpful! I've got a question at the moment - how a browser controlled by selenium webdriver deals with permanent cookies? For example, I login into a site, checked Remember be and close the browser session. The run webdriver again and navigate to the same site and see that the login information was cleared and I have to login again. Will you clarify what happens here and how deal with it? Thanks a lot in advance.
Hi Igor, Selenium always starts a fresh browser session when you call the webdriver. Can check here www.selenium.dev/documentation/webdriver/interactions/cookies/
@@RaghavPal Thanks, Raghav! It looks like WebDiver witn a browser work in a kind of "virtual machine". They know nothing about other browser session. I tried to install an broser extension - no problem. But when I started new webdriver sesiion the browser didn't have the etension. Frankly speaking, I feel there can be problems with such approach.
Hi Igor, that is because webdriver opens a new profile of the browsers, in case you want to use your desktop profile of the browser, where you have added extensions etc, you can specify that in Desired Capabilities
Here is a discussion for Firefox - stackoverflow.com/questions/71474700/unable-to-load-existing-firefox-profile-with-selenium-4s-option-set-preference
@@RaghavPal Hi Raghav, thanks a lot for the information! It helps me in my investigations of the topic. By the way, do you know if there are 'profiles' in Chrome and Edge which can be used with webdriver?
after saving maven dependencies not showing can u help me
Hi Diksha
There are a few reasons why Maven dependencies might not be showing in Eclipse after saving. Here are some things you can check:
* Make sure that the Maven project is properly configured. You can do this by opening the project properties and checking the Maven tab.
* Make sure that the Maven dependencies are downloaded. You can do this by running the Maven `clean` and `install` goals.
* Make sure that the Maven dependencies are visible in the Eclipse project explorer. You can do this by expanding the Maven Dependencies node.
If you have checked all of these things and the Maven dependencies are still not showing, you can try the following:
* Restart Eclipse.
* Clear the Maven cache. You can do this by running the Maven `clean` goal.
* Reimport the Maven project. You can do this by right-clicking on the project in the Eclipse project explorer and selecting the "Maven" > "Reimport" menu item.
If you are still having trouble, you can search for the error message on the Maven website or on Stack Overflow to see if there are any other solutions.
Here are some additional things you can check:
* Make sure that you are using the latest version of Maven.
* Try starting Maven manually and see if it downloads the dependencies without any problems.
* If you are using a proxy, make sure that the proxy settings are correct.
* If you are using a firewall, make sure that it is not blocking Maven.
I hope this helps
Hi need code for 2 questions can u provide me with that...
or you can make a video on that??
Hi Premashri, pls let me know your queries
good video but im stuck at the 11:41 mark, when i hover over the webdriver i dont have the import WebDriver option. i got the create class and change to chrome driver and when i do that i still get a error i been stuck on this for a min, can you help me fix this problem ? thank you
Paul
for the issue with importing the WebDriver class in your Selenium Java project.. this is typically due to the Selenium WebDriver library not being properly added to your project's build path. Here's how you can fix this:
1. Ensure Selenium WebDriver is Added to Your Project:
- If you're using Maven, make sure the Selenium WebDriver dependency is included in your `pom.xml` file.
- If you're not using Maven, download the Selenium WebDriver `.jar` files from the Selenium website and add them to your project's build path.
2. Check Your IDE's Import Suggestions:
- Sometimes, IDEs like Eclipse may not immediately suggest the correct import statements. Try typing the import statement manually:
```java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
```
- After typing it manually, if the classes are still not recognized, it's likely an issue with how the libraries are referenced in your project.
3. Refresh Your Project:
- In Eclipse, right-click on your project and select `Refresh`. This can help the IDE recognize newly added libraries.
4. Clean and Rebuild Your Project:
- Use the `Clean` and `Build` options in your IDE to rebuild your project, which can sometimes resolve issues with unrecognized imports.
5. Check for Correct WebDriver Version:
- Ensure that the version of ChromeDriver you're using is compatible with the browser version installed on your machine.
6. Set the System Property Correctly:
- Before creating an instance of `ChromeDriver`, set the system property correctly with the path to your `chromedriver.exe`:
```java
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");
WebDriver driver = new ChromeDriver();
```
..
i am using Maven and i checked and it doesn't have the selenium web driver how do i add the selenium web driver? i went to the market place and tried to download it and i couldn't find it there. also when i manually add the import org.openqa.selenium.WebDriver; the red line goes away from webdriver but now i have a yellow line under driver. so the line of code looks like this " WebDriver driver = new ChromeDriver();" and under driver is a yellow line. i hover over it and it says the value of the local driver is not used. @@RaghavPal i really appreciate all the help!
To add Selenium WebDriver to your Maven project, you need to include the Selenium WebDriver dependency in your `pom.xml` file. Here's how you can do it:
1. Open your `pom.xml` file.
2. Add the following dependency for Selenium WebDriver:
```xml
org.seleniumhq.selenium
selenium-java
3.141.59
```
Make sure to replace the version number with the latest version available.
Regarding the yellow line under `driver`, it's a warning indicating that the `driver` variable is declared but not used anywhere else in your code. This is common when you've just set up the driver and haven't added any code to use it yet. Once you start using the `driver` variable to interact with web pages, the warning should disappear.
If you're seeing a yellow line and the message "the value of the local variable driver is not used," it means that you have instantiated the `ChromeDriver`, but you haven't used it to perform any actions. As soon as you add more code to use the `driver`, such as navigating to a webpage or interacting with web elements, this warning should go away.
Here's an example of using the `driver` to navigate to a webpage:
```java
WebDriver driver = new ChromeDriver();
driver.get("www.example.com"); // Replace with the URL you want to navigate to
// Add your code to interact with the webpage here
```
Remember to download the ChromeDriver executable and set the system property for `webdriver.chrome.driver` to its path before instantiating `ChromeDriver`
ok i have the xml already on there with the latest version also when i added the driver.get the yellow line went away, i added google in the example to get it to open google and it didnt and the console im getting this error
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:359)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:684)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:666)
@@RaghavPal
The error message you’re encountering-java.lang.UnsupportedClassVersionError-indicates a version mismatch between the Java Runtime Environment (JRE) used for compilation and the JRE used for execution
Hi Raghav Sir..I am new to IT field..basically from mechanical backgrown...i am following your sunday videos which sent by one my friend..i motivated from that videos..i want to learn and step in to this S/W side...What your suggetion..I done B.tech Mech in 2009 and M.tech in mech 2017...due some reason present my working field is vanished...
Hi, you can first check and analyse what you are interested in, IT is a huge field, select a subject, skill and learn about it, read some reviews, get some knowledge, follow some basic tutorials, so you get some good insight and then you can take a decision
@@RaghavPal thank you..sir.
Now i started viewing videos of QnA Friday..tonight i will complete
Hi Raghav Sir ..3 months back i msgd you about my career..I got jobs in INFOSYS AND TCS As performance test engineer..Really this credit goes to you only..thank you sir...for motivating me from your videos..pls share your mail Id..
Thanks lot
Hello Raghav,
I need a bit of help, please help.
And always great work with the videos that you've made 👍
How can I help you?
Cool demo. I am looking to buy a course to learn Selenium 4.X with Python. Do you have one?
I have free courses here - community.postman.com/t/how-to-handle-dynamic-jsonpath/5949
Which jdk version is compatible with selenium 4? please reply soon. Thank you
Hi Shailendra, Selenium 4 is compatible with JDK 8 or later. However, it is recommended to use the latest version of JDK available.
@@RaghavPal Thank you RaghavPal ji I have learnt alot from your videos. Please continue to enrich and enhance our knowledge by creating such nice, concise and sharp content videos. 👌
Sir I am BCA passout student of 2020 batch and I have a gap of one year after my 12th...can i get a job as QA.. please tell me the roadmap
Hi, yes, should not be any problem
why u create main method in springboot application?
It's normal java here
Are you going to do a series on Selenium 4 + Cucumber BDD ?
Hi, the existing selenium cucumber series will work for Se 4 as well, I will check and plan if a new playlist is needed
@@RaghavPal Yeah it would be helpful if a new playlist is created
Can u plz add how to work with tables
I will plan a session
Hello Sir,
Why new Tab is Opening in Original Windows?
IF we are switching to New Windows and then we are using new Command for opening Tab.Tab is opening in original windows?
Hi Ravi, will need to see your code
@@RaghavPal i am talking about this tutorial video
@@RaghavPal Sir I am talking about this tutorial Duration on 32 min to 35 min.
We are opening New Window and then next command is opening new Tab so new tab is opening in Original Windows instead of NewWindow.
ok, will check this
Sir please make complete tutorial for selenium web driver 4
I will plan Durgesh
Hi sir
Can you please suggest some chrome extensions to find the XPATH ?
Hi Reshma, xpath finder can help
ranorex selocity is also good
Broo, my Hello Wolrd can not show in console log. My code is same with your code in video.
Hi Heri, will need to check the setup
@@RaghavPal yes sure
Hi Raghav, I want to move from dev to testing for which i need to do some courses, could you please suggest me some good courses to get job and also please tell i have 1 year of experience in java so will it be wasted while moving to testing.. Thanks in advance,waiting for ur reply.
Hi Shivam, you can try automation testing and start with Selenium Java Framework, Can get the sections here - automationstepbystep.com/
@@RaghavPal Also please guide me if i switch from java to testing will my 1 year experience be wasted?or i can get experience level job in testing
No, if you are going into Automation, SDET, DevOps, there programming knowledge is helpful
Hi Raghav , facing difficulties in suggestion , please suggest needful
Sara
let me know the ques and details
Is it possible to completely automate the CI CD pipeline
Awaiting your reply
Yes, you can do Balaji, it will involve automation of all the sections of your project or delivery pipeline
@@RaghavPal May I know the tools involved to automate the job run in Jenkins and other DevOps processes
Could you give me a high level workflow on the process of automation the entire pipeline
Sure Balaji, Before you proceed understand the process and steps
Process - ruclips.net/video/iKex0vqttiU/видео.html
Steps - ruclips.net/video/KrVezx3E8OQ/видео.html
I am beginner in selenium... From which one video i can start!? Selenium 4!? Or the the beginner video!?
You can do Selenium 4 series Can find all here - automationstepbystep.com/
Hi ,
Please make one session on BAZEL build tool
I will check and plan Nagarjuna
i have some different xpaths pls helpme
Hi Sirisha, you can check xpath tutorial - ruclips.net/p/PLhW3qG5bs-L83gLEZVIDHOvgTTz27po_0
Hi sir , do videos on cucumber selenium with nodejs
Please
I will plan Navin
@@RaghavPal thankyou so much
Can you please video simultaneously selenium with python and pytest
I will plan Sabitri
@@RaghavPal thanks a lot will be surely waiting
Hi ,
I m currently working as a manual tester , planning to switch into Automation Testing,
I heard that 10 yrs experienced tester can be easily replaced with 5 yrs experienced tester for cost cutting, So that 10 yrs experienced tester will loose the job !
And also people say that ,
In dev 10 yrs experienced dev cannot be replaced by 5 yrs experienced dev in any company unlike Testers , is that true ?
Please reply
Does testers don't have life after 10/15 yrs work experience? Is it worth learning and putting efforts in Automation Testing and choosing it as an Career option?
please clarify this.
Hi, This is not so straight forward, there are several aspects to consider, I will try to do a session here
@@RaghavPal thanks, Will be waiting to watch the session sooner
What about python +Selenium 4 sir?
I will make some sessions
Hi Raghav,
Can you please add video with example for ScriptTimeOut.
I will Amit, send me some reference links to check
@@RaghavPal Are you asking for application URL?
No, I just wanted to know from where did you refer the script time out issues
@@RaghavPal I haven't used script timeout in my code. I have just gone through this video where you have talked about script timeout. So I just wanted to get idea how I can implement this in real time code.
ok, I will check