Thanks for another informative video. I was using below code to select "option 2" but it select - option 1, option 2, option 3 in order. List optionsDropDownElement = selectObject.getOptions();
Harsh It seems there's a small issue in your code snippet. The semicolon after the `if` statement is causing the unexpected behavior. Let's correct it! Here's the revised version of your code: ```java List optionsDropDownElement = selectObject.getOptions(); for (WebElement option : optionsDropDownElement) { System.out.println(option.getText()); if (option.getText().equalsIgnoreCase("option 2")) { option.click(); Thread.sleep(1000); } } ``` Now, with this corrected code, it should select "Option 2" as expected. Happy testing..
Thank you for your videos, they are a great help. I wanted to ask if there is a way to create an executable project, such as ".exe", with the scripts we create automation. It would also be interesting to visualize a project moving forward with everything we learned, unit tests, automated tests and reports so that the summary of results is visualized. Greetings and a big hug, let us aggrandize your knowledge!
Hi @Raghav .Thanks for Your efforts.. Could You please help us the some more challenging scenarios with waits. And Dropdown with dynamic element, Dropdown with checkBox ..How to Locate element inside the Dropdown like checkBox Selection with List etc
Hi Sir, I have learned a lot from you. Sir can you help me, that How can I work with Angular Material drop-down. In selenium java. Because selenium supports Select component. But in my case it is mat-select
Iftikhar Yes. Angular Material drop-downs are not regular select components, so you can't use Selenium's Select class to interact with them. However, there are a few ways to work with them using Selenium Java. **One way is to use the `findElement()` method to locate the dropdown element and then use the `click()` method to click on it.** This will open the dropdown menu. You can then use the `findElements()` method to locate the dropdown options and then use the `click()` method to click on the option you want to select. The following code shows how to use this method to select the "First Option" option from an Angular Material dropdown: ```java WebElement dropdown = driver.findElement(By.cssSelector("mat-select[name='myDropdown']")); dropdown.click(); List options = driver.findElements(By.cssSelector("mat-option")); for (WebElement option : options) { if (option.getText().equals("First Option")) { option.click(); break; } } ``` **Another way to work with Angular Material dropdowns is to use the `Actions` class.** The `Actions` class allows you to perform complex interactions with elements on a web page, such as hovering over elements, clicking and dragging, and right-clicking. To use the `Actions` class to select an option from an Angular Material dropdown, you can use the following code: ```java Actions actions = new Actions(driver); WebElement dropdown = driver.findElement(By.cssSelector("mat-select[name='myDropdown']")); WebElement option = driver.findElement(By.cssSelector("mat-option[value='first-option']")); actions.moveToElement(dropdown).click().perform(); actions.moveToElement(option).click().perform(); ``` This code will first move the mouse cursor to the dropdown element and click on it. This will open the dropdown menu. Then, the code will move the mouse cursor to the "First Option" option and click on it. This will select the "First Option" option from the dropdown. **Which method you use to work with Angular Material dropdowns is up to you.** I recommend using the `Actions` class, as it is more flexible and allows you to perform more complex interactions with elements on a web page. I hope this helps
thanks dear Teacher. is there any way that I can reach out to you please. I really appreicaite all you support and help. the best teacher in the world. I hope i can meet you one day brother .
Hi Raghav Sir ,Could you please help us to understand which tool will dominate the SELENIUM in near future to accommodate every kind of tester . Also there are license tools available which focuses on core things with less maintenance of control identification and auto sync mechanism but still companies are not using . If companies are really wants to get better ROI and less maintenance then they should be using ,instead sticking with Selenium which is more programming dependent as we see so many application development tools /framework which has declarative coding rather than programming style same way testing Automation tools are there like KATALON,Tosca but still hearing SELENIUM and the managers who are not even supporting technically asking SELENIUM as default . Could you please help us here with
Hi, In general Selenium has been an industry standard for UI browser automation and it is used by a lot of paid tools as their backend. I do understand that today as we have multiple options with paid tools to save on scripting and maintenance, there are many options. I will suggest to create a chart, table listing out your requirements and having columns to compare tools against each requirement, So it will be Selenium and other options, Here also have columns for time needed, efforts and return on investment, If you do this analysis and then present to your seniors, I am sure, it will have a different impact. I will too try to create a session on this
Hi raghav, Need help When i launch edge browser from script it launch with side bar need to hide it by setting desired capabilities Not getting way how to do that. Please help
Hi Pravin, this examples is for Selenium with C# stackoverflow.com/questions/62340984/selenium-c-sharp-to-disable-microsoft-chromium-edge-browser-sync-pop-up Can do similar in Java
Hi Raghav, I am on it dropdown valuse selection.There is major class dropdown in my project which has 5 options i have to select 4th value i tried this menthod but it did not work .I can see when i inspected the element i could not see select class , its div class as below. Major Class I wrote below script and tried few more xpaths but its not locating. WebElement dropdownElement = driver.findElement(By.xpath("//div[@class='react-select__placeholder' and text()='Major Class']")); // Replace with the actual ID of your dropdown Select dropdown= new Select(dropdownElement); dropdown.selectByIndex(2); dropdown.selectByVisibleText("Excess Casualty"); Thread.sleep(2000);
Kavita The reason why your Selenium Java script is not working is because the dropdown element is not a `` element. It is a custom dropdown element that uses the React Select library To select an option from a custom dropdown element using Selenium, you can use the following steps: 1. Locate the dropdown element using an XPath or CSS selector. 2. Click on the dropdown element to open the dropdown list. 3. Locate the option you want to select in the dropdown list. 4. Click on the option to select it. Here is an example of how to select the fourth option from the dropdown element you provided using Selenium Java: ```java WebElement dropdownElement = driver.findElement(By.xpath("//div[@class='react-select__placeholder' and text()='Major Class']")); // Click on the dropdown element to open the dropdown list. dropdownElement.click(); // Locate the fourth option in the dropdown list. WebElement optionElement = driver.findElement(By.xpath("//div[@class='react-select__option-container']//div[text()='Excess Casualty']")); // Click on the option to select it. optionElement.click(); ``` You can also use the Playwright API to select an option from a custom dropdown element. However, this is a more complex topic and I would recommend using Selenium if you are not familiar with Playwright. I hope this helps
is there any way i can attach the image?Means is there any way or forum you have created so than we can show you with more details .thanks for reply in details
Hi sir, I hav one doubt regarding webpage validation, in real time, is it required to validate (web elements like button,titles ,screens and content etc) . Font color,font family,font size and background colors. Please reply me.
The red line in the dropdown is likely caused by an error in your Selenium code. This can happen for a number of reasons, such as: * You are trying to select an option from a dropdown that does not exist. * You are using the wrong syntax to select an option from a dropdown. * The dropdown is not visible on the page. * There is an element on the page that is blocking the dropdown. To troubleshoot the problem, you can try the following: 1. Make sure that the dropdown exists on the page. You can use the `findElement()` method to find the dropdown element. 2. Make sure that you are using the correct syntax to select an option from the dropdown. You can use the `selectByVisibleText()`, `selectByIndex()`, or `selectByValue()` method to select an option from the dropdown. 3. Make sure that the dropdown is visible on the page. You can use the `isDisplayed()` method to check if the dropdown is visible. 4. If the dropdown is not visible, try scrolling the page to make it visible. 5. If there is an element on the page that is blocking the dropdown, try moving the element out of the way. If you are still having problems, you can post your code and the error message that you are getting, and I will try to help you troubleshoot the problem. Here is an example of a correct Selenium code snippet to select an option from a dropdown: ```java WebElement dropdown = driver.findElement(By.id("my-dropdown")); Select select = new Select(dropdown); select.selectByVisibleText("My Option"); ``` If you are getting a red line when you try to run this code, it is likely because the dropdown element does not exist on the page. Make sure that you have the correct XPath or CSS selector for the dropdown element. I hope this helps
Ankit In Selenium, when interacting with dropdowns (also known as select elements), using the `.select_by_value()`, `.select_by_index()`, or `.select_by_visible_text()` methods from the `Select` class is preferred over the `.click()` method. Let me explain why: 1. Purpose: - Dropdowns are specifically designed to allow users to select an option from a list. They have a structured format that includes options with values and visible text - The `.select_by_*()` methods provide a way to interact with these dropdowns by directly choosing an option based on its value, index, or visible text 2. `.click()` Method: - The `.click()` method simulates a mouse click on an element. While it can technically open a dropdown, it doesn't guarantee that an option will be selected - After clicking, you'd need additional steps to locate and click the desired option, which is cumbersome and error-prone 3. Benefits of `.select_by_*()` Methods: - Explicit Selection: These methods allow you to explicitly choose an option by specifying its value, index, or visible text. This ensures accurate selection - Validation: When you use `.select_by_*()`, Selenium validates that the specified option exists in the dropdown. If not, it raises an exception, preventing accidental selection of non-existent options - Efficiency: `.select_by_*()` directly interacts with the dropdown's internal structure, making it more efficient than multiple `.click()` actions 4. Example Usage: ```python from selenium.webdriver.support.ui import Select # Assuming 'driver' is your WebDriver instance dropdown_element = driver.find_element_by_id("my-dropdown") dropdown = Select(dropdown_element) # Select by value dropdown.select_by_value("option-value") # Select by visible text dropdown.select_by_visible_text("Option Text") # Select by index (0-based) dropdown.select_by_index(2) ``` In summary, prefer using `.select_by_*()` methods for dropdowns to ensure accurate selection and better maintainability -
Hi Raghav i am trying to fetch some values from dropdown but getting error org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: I am unable to find the correct Path this is the value that i want to get from dropdown. can you help with this please, stuck from a long time
@@RaghavPal Thank you for the reply Raghav what is the masking i do not have any idea (means if any element is present on this or not right?) But how should i check this.....it looks like the other dropdowns,also this is comes on the modal. i have tried wit the wait but still not working
Hi Raghav, I'm learning Appium by watching your tutorial Raghav. If I running getting an error like this java.lang.IncompatibleClassChangeError: class io.appium.java_client.AppiumExecutionMethod can not implement org.openqa.selenium.remote.ExecuteMethod, because it is not an interface (org.openqa.selenium.remote.ExecuteMethod is in unnamed module of loader 'app') please Raghav help me out with this issue
Hi Raghav, still am not fix it out now got Exception like Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Appium Settings app is not running after 5000ms
@@sathiksha3654 @Automation Step by Step Hi Raghav Even i am facing the same issue when i am performing the execution in Mobile Can you help me on this??
This selenium 4 course is very nice and beginner friendly. It really gave me a starting point and direction. Thanks for these free videos. :)
You're very welcome!
🙏🙏Your tech teaching style is really effective. I'm learning so much. Thank you
You are very welcome 🙏
Thank you, Raghav, and please keep up the good work!
Thanks Svetlana
Thanks for another informative video. I was using below code to select "option 2" but it select - option 1, option 2, option 3 in order.
List optionsDropDownElement = selectObject.getOptions();
for(WebElement option: optionsDropDownElement) {
System.out.println(option.getText());
if(option.getText().equalsIgnoreCase("option 2"));
option.click();
Thread.sleep(1000);
}
Harsh
It seems there's a small issue in your code snippet. The semicolon after the `if` statement is causing the unexpected behavior.
Let's correct it! Here's the revised version of your code:
```java
List optionsDropDownElement = selectObject.getOptions();
for (WebElement option : optionsDropDownElement) {
System.out.println(option.getText());
if (option.getText().equalsIgnoreCase("option 2")) {
option.click();
Thread.sleep(1000);
}
}
```
Now, with this corrected code, it should select "Option 2" as expected. Happy testing..
Thankyou Raghav for this wonderful selenium 4 course. It's very helpful for beginners. Thanks!
Most welcome Shahzaib
I am waiting for this thank u Sir!! ❤️
Most welcome Saurabh
Thank you for your videos, they are a great help.
I wanted to ask if there is a way to create an executable project, such as ".exe", with the scripts we create automation. It would also be interesting to visualize a project moving forward with everything we learned, unit tests, automated tests and reports so that the summary of results is visualized.
Greetings and a big hug, let us aggrandize your knowledge!
Hi Fraven, instead of .exe, you can use maven project and run from command line, I will add more sessions, can check here - automationstepbystep.com/
Thanks... Waiting for this part❤️
You're welcome Anuj
Thanks Raghav.. Excellent tutorial ✌🏼
Glad you liked it Syed
Thanks. As always, that was a great video.
Most welcome
Hi @Raghav .Thanks for Your efforts.. Could You please help us the some more challenging scenarios with waits. And Dropdown with dynamic element, Dropdown with checkBox ..How to Locate element inside the Dropdown like checkBox Selection with List etc
Hi Shashikant, I will add more sessions
great video, thank you!
You are welcome
Hi Sir, I have learned a lot from you. Sir can you help me, that How can I work with Angular Material drop-down. In selenium java. Because selenium supports Select component. But in my case it is mat-select
Iftikhar
Yes. Angular Material drop-downs are not regular select components, so you can't use Selenium's Select class to interact with them. However, there are a few ways to work with them using Selenium Java.
**One way is to use the `findElement()` method to locate the dropdown element and then use the `click()` method to click on it.** This will open the dropdown menu. You can then use the `findElements()` method to locate the dropdown options and then use the `click()` method to click on the option you want to select.
The following code shows how to use this method to select the "First Option" option from an Angular Material dropdown:
```java
WebElement dropdown = driver.findElement(By.cssSelector("mat-select[name='myDropdown']"));
dropdown.click();
List options = driver.findElements(By.cssSelector("mat-option"));
for (WebElement option : options) {
if (option.getText().equals("First Option")) {
option.click();
break;
}
}
```
**Another way to work with Angular Material dropdowns is to use the `Actions` class.** The `Actions` class allows you to perform complex interactions with elements on a web page, such as hovering over elements, clicking and dragging, and right-clicking.
To use the `Actions` class to select an option from an Angular Material dropdown, you can use the following code:
```java
Actions actions = new Actions(driver);
WebElement dropdown = driver.findElement(By.cssSelector("mat-select[name='myDropdown']"));
WebElement option = driver.findElement(By.cssSelector("mat-option[value='first-option']"));
actions.moveToElement(dropdown).click().perform();
actions.moveToElement(option).click().perform();
```
This code will first move the mouse cursor to the dropdown element and click on it. This will open the dropdown menu. Then, the code will move the mouse cursor to the "First Option" option and click on it. This will select the "First Option" option from the dropdown.
**Which method you use to work with Angular Material dropdowns is up to you.** I recommend using the `Actions` class, as it is more flexible and allows you to perform more complex interactions with elements on a web page.
I hope this helps
thanks dear Teacher. is there any way that I can reach out to you please. I really appreicaite all you support and help. the best teacher in the world. I hope i can meet you one day brother .
So happy & humbled to see your message
Thanks
Welcome Vishal
Hi Raghav Sir ,Could you please help us to understand which tool will dominate the SELENIUM in near future to accommodate every kind of tester . Also there are license tools available which focuses on core things with less maintenance of control identification and auto sync mechanism but still companies are not using . If companies are really wants to get better ROI and less maintenance then they should be using ,instead sticking with Selenium which is more programming dependent as we see so many application development tools /framework which has declarative coding rather than programming style same way testing Automation tools are there like KATALON,Tosca but still hearing SELENIUM and the managers who are not even supporting technically asking SELENIUM as default . Could you please help us here with
Hi, In general Selenium has been an industry standard for UI browser automation and it is used by a lot of paid tools as their backend. I do understand that today as we have multiple options with paid tools to save on scripting and maintenance, there are many options.
I will suggest to create a chart, table listing out your requirements and having columns to compare tools against each requirement, So it will be Selenium and other options, Here also have columns for time needed, efforts and return on investment,
If you do this analysis and then present to your seniors, I am sure, it will have a different impact.
I will too try to create a session on this
Hello sir. After this selenium for beginners part. what is the next next part we have to learn?
You can go for more tools in UI testing or do CI CD tools like Jenkins and API testing, can check the sections here - automationstepbystep.com/
hello,
should I learn selenium or cypress?
I've no knowledge of any of the tool, neither the langguage java, node js or javascript
Hi Shubham, you can start with Cypress
Hi raghav,
Need help
When i launch edge browser from script it launch with side bar need to hide it by setting desired capabilities
Not getting way how to do that. Please help
Using selenium 3.x
Hi Pravin, this examples is for Selenium with C#
stackoverflow.com/questions/62340984/selenium-c-sharp-to-disable-microsoft-chromium-edge-browser-sync-pop-up
Can do similar in Java
Do you have automation course please online ? I want to learn from you.
Hi, can check all here - automationstepbystep.com/
Hi Raghav, I am on it dropdown valuse selection.There is major class dropdown in my project which has 5 options i have to select 4th value i tried this menthod but it did not work .I can see when i inspected the element i could not see select class , its div class as below.
Major Class
I wrote below script and tried few more xpaths but its not locating.
WebElement dropdownElement = driver.findElement(By.xpath("//div[@class='react-select__placeholder' and text()='Major Class']")); // Replace with the actual ID of your dropdown
Select dropdown= new Select(dropdownElement);
dropdown.selectByIndex(2);
dropdown.selectByVisibleText("Excess Casualty");
Thread.sleep(2000);
Kavita
The reason why your Selenium Java script is not working is because the dropdown element is not a `` element. It is a custom dropdown element that uses the React Select library
To select an option from a custom dropdown element using Selenium, you can use the following steps:
1. Locate the dropdown element using an XPath or CSS selector.
2. Click on the dropdown element to open the dropdown list.
3. Locate the option you want to select in the dropdown list.
4. Click on the option to select it.
Here is an example of how to select the fourth option from the dropdown element you provided using Selenium Java:
```java
WebElement dropdownElement = driver.findElement(By.xpath("//div[@class='react-select__placeholder' and text()='Major Class']"));
// Click on the dropdown element to open the dropdown list.
dropdownElement.click();
// Locate the fourth option in the dropdown list.
WebElement optionElement = driver.findElement(By.xpath("//div[@class='react-select__option-container']//div[text()='Excess Casualty']"));
// Click on the option to select it.
optionElement.click();
```
You can also use the Playwright API to select an option from a custom dropdown element. However, this is a more complex topic and I would recommend using Selenium if you are not familiar with Playwright.
I hope this helps
Thanks fro details answer i will try this, playwright i dnt know so other options you suggested i will try.
@@RaghavPal
I tried this script but it did not work its not locating the dropdown , i also tried such many ways but nothing is working@@RaghavPal
is there any way i can attach the image?Means is there any way or forum you have created so than we can show you with more details .thanks for reply in details
can upload image on some image sharing site and share the link
Hi, Is there any difference in dropdown between Selenium 3 vs 4?
methods are same
What is the next step? What to learn?
Can check all Selenium tutorials here - automationstepbystep.com/
Hi sir, I hav one doubt regarding webpage validation, in real time, is it required to validate (web elements like button,titles ,screens and content etc) . Font color,font family,font size and background colors. Please reply me.
You can if needed, can use tools like Applitools - ua-cam.com/video/ItutKRrq0JI/v-deo.html
Thanks you so much.
@@RaghavPal Thanks Raghav...for Your Selfless efforts.You are doing great work.please continue it
selectobject is showing a red line in my drop down
The red line in the dropdown is likely caused by an error in your Selenium code. This can happen for a number of reasons, such as:
* You are trying to select an option from a dropdown that does not exist.
* You are using the wrong syntax to select an option from a dropdown.
* The dropdown is not visible on the page.
* There is an element on the page that is blocking the dropdown.
To troubleshoot the problem, you can try the following:
1. Make sure that the dropdown exists on the page. You can use the `findElement()` method to find the dropdown element.
2. Make sure that you are using the correct syntax to select an option from the dropdown. You can use the `selectByVisibleText()`, `selectByIndex()`, or `selectByValue()` method to select an option from the dropdown.
3. Make sure that the dropdown is visible on the page. You can use the `isDisplayed()` method to check if the dropdown is visible.
4. If the dropdown is not visible, try scrolling the page to make it visible.
5. If there is an element on the page that is blocking the dropdown, try moving the element out of the way.
If you are still having problems, you can post your code and the error message that you are getting, and I will try to help you troubleshoot the problem.
Here is an example of a correct Selenium code snippet to select an option from a dropdown:
```java
WebElement dropdown = driver.findElement(By.id("my-dropdown"));
Select select = new Select(dropdown);
select.selectByVisibleText("My Option");
```
If you are getting a red line when you try to run this code, it is likely because the dropdown element does not exist on the page. Make sure that you have the correct XPath or CSS selector for the dropdown element.
I hope this helps
thank u my great friend....i love you@@RaghavPal
Why select why not .click() method?
Ankit
In Selenium, when interacting with dropdowns (also known as select elements), using the `.select_by_value()`, `.select_by_index()`, or `.select_by_visible_text()` methods from the `Select` class is preferred over the `.click()` method. Let me explain why:
1. Purpose:
- Dropdowns are specifically designed to allow users to select an option from a list. They have a structured format that includes options with values and visible text
- The `.select_by_*()` methods provide a way to interact with these dropdowns by directly choosing an option based on its value, index, or visible text
2. `.click()` Method:
- The `.click()` method simulates a mouse click on an element. While it can technically open a dropdown, it doesn't guarantee that an option will be selected
- After clicking, you'd need additional steps to locate and click the desired option, which is cumbersome and error-prone
3. Benefits of `.select_by_*()` Methods:
- Explicit Selection: These methods allow you to explicitly choose an option by specifying its value, index, or visible text. This ensures accurate selection
- Validation: When you use `.select_by_*()`, Selenium validates that the specified option exists in the dropdown. If not, it raises an exception, preventing accidental selection of non-existent options
- Efficiency: `.select_by_*()` directly interacts with the dropdown's internal structure, making it more efficient than multiple `.click()` actions
4. Example Usage:
```python
from selenium.webdriver.support.ui import Select
# Assuming 'driver' is your WebDriver instance
dropdown_element = driver.find_element_by_id("my-dropdown")
dropdown = Select(dropdown_element)
# Select by value
dropdown.select_by_value("option-value")
# Select by visible text
dropdown.select_by_visible_text("Option Text")
# Select by index (0-based)
dropdown.select_by_index(2)
```
In summary, prefer using `.select_by_*()` methods for dropdowns to ensure accurate selection and better maintainability
-
Thanks a lot ❤@@RaghavPal
hi sir can u please provide all source codes?
Ok Yash, will add this to GitHub
↓↓
@@RaghavPal thanks
Hi Raghav i am trying to fetch some values from dropdown but getting error org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
I am unable to find the correct Path
this is the value that i want to get from dropdown. can you help with this please, stuck from a long time
Hi Antara, check
1. the element locators are correct
2. add some wait
3. check the element is not masked
@@RaghavPal Thank you for the reply Raghav
what is the masking i do not have any idea (means if any element is present on this or not right?)
But how should i check this.....it looks like the other dropdowns,also this is comes on the modal.
i have tried wit the wait but still not working
masking is when some element is hidden or over shadowed by any other element
you should also check if the element is inside a frame
@@RaghavPal ok Thanks Raghav
Hi Raghav, I'm learning Appium by watching your tutorial Raghav. If I running getting an error like this java.lang.IncompatibleClassChangeError: class io.appium.java_client.AppiumExecutionMethod can not implement org.openqa.selenium.remote.ExecuteMethod, because it is not an interface (org.openqa.selenium.remote.ExecuteMethod is in unnamed module of loader 'app') please Raghav help me out with this issue
HI Sathhik, you must be getting a caused by section in the logs, pls check
@@RaghavPal Thanks Raghav,
Hi Raghav, still am not fix it out now got Exception like Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Appium Settings app is not running after 5000ms
@@sathiksha3654 @Automation Step by Step Hi Raghav Even i am facing the same issue when i am performing the execution in Mobile Can you help me on this??
I will check on this and update as I get some info