Selenium 4 Beginner Tutorial 10 | How to handle DropDown

Поділитися
Вставка
  • Опубліковано 15 вер 2024

КОМЕНТАРІ • 82

  • @priyanshisaxena1822
    @priyanshisaxena1822 2 роки тому +2

    This selenium 4 course is very nice and beginner friendly. It really gave me a starting point and direction. Thanks for these free videos. :)

  • @Varun-A
    @Varun-A Рік тому +1

    🙏🙏Your tech teaching style is really effective. I'm learning so much. Thank you

  • @svetlanamazhaykina6918
    @svetlanamazhaykina6918 2 роки тому +1

    Thank you, Raghav, and please keep up the good work!

  • @flirtuall78
    @flirtuall78 5 місяців тому

    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);

    }

    • @RaghavPal
      @RaghavPal  5 місяців тому

      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..

  • @shahzaibidreesahmed4827
    @shahzaibidreesahmed4827 Рік тому

    Thankyou Raghav for this wonderful selenium 4 course. It's very helpful for beginners. Thanks!

  • @saurabhshirke7329
    @saurabhshirke7329 2 роки тому +1

    I am waiting for this thank u Sir!! ❤️

    • @RaghavPal
      @RaghavPal  2 роки тому +1

      Most welcome Saurabh

  • @fraven9586
    @fraven9586 2 роки тому +2

    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!

    • @RaghavPal
      @RaghavPal  2 роки тому

      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/

  • @anujupadhyay4963
    @anujupadhyay4963 2 роки тому +1

    Thanks... Waiting for this part❤️

  • @syedarmaghanhassan4652
    @syedarmaghanhassan4652 11 місяців тому

    Thanks Raghav.. Excellent tutorial ✌🏼

    • @RaghavPal
      @RaghavPal  11 місяців тому

      Glad you liked it Syed

  • @SineQuaNon1
    @SineQuaNon1 Рік тому

    Thanks. As always, that was a great video.

  • @shashikantgaurav1689
    @shashikantgaurav1689 2 роки тому +2

    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

    • @RaghavPal
      @RaghavPal  2 роки тому +2

      Hi Shashikant, I will add more sessions

  • @softwaretestinglearninghub
    @softwaretestinglearninghub Рік тому

    great video, thank you!

  • @iftikharhussain1823
    @iftikharhussain1823 10 місяців тому

    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

    • @RaghavPal
      @RaghavPal  10 місяців тому

      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

  • @loveandlike6747
    @loveandlike6747 2 роки тому

    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 .

    • @RaghavPal
      @RaghavPal  2 роки тому

      So happy & humbled to see your message

  • @vishalwin
    @vishalwin 2 роки тому

    Thanks

  • @roshnray6566
    @roshnray6566 2 роки тому

    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

    • @RaghavPal
      @RaghavPal  2 роки тому

      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

  • @DurgaPrasad-fh4nz
    @DurgaPrasad-fh4nz Рік тому

    Hello sir. After this selenium for beginners part. what is the next next part we have to learn?

    • @RaghavPal
      @RaghavPal  Рік тому

      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/

  • @shubhamverma1037
    @shubhamverma1037 2 роки тому

    hello,
    should I learn selenium or cypress?
    I've no knowledge of any of the tool, neither the langguage java, node js or javascript

    • @RaghavPal
      @RaghavPal  2 роки тому +1

      Hi Shubham, you can start with Cypress

  • @pravinjadhav9749
    @pravinjadhav9749 Рік тому

    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

    • @pravinjadhav9749
      @pravinjadhav9749 Рік тому

      Using selenium 3.x

    • @RaghavPal
      @RaghavPal  Рік тому

      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

  • @loveandlike6747
    @loveandlike6747 2 роки тому

    Do you have automation course please online ? I want to learn from you.

    • @RaghavPal
      @RaghavPal  2 роки тому

      Hi, can check all here - automationstepbystep.com/

  • @KavitaRawatWorld
    @KavitaRawatWorld Рік тому

    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);

    • @RaghavPal
      @RaghavPal  Рік тому +1

      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

    • @KavitaRawatWorld
      @KavitaRawatWorld Рік тому

      Thanks fro details answer i will try this, playwright i dnt know so other options you suggested i will try.
      @@RaghavPal

    • @KavitaRawatWorld
      @KavitaRawatWorld Рік тому

      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

    • @KavitaRawatWorld
      @KavitaRawatWorld Рік тому

      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

    • @RaghavPal
      @RaghavPal  Рік тому

      can upload image on some image sharing site and share the link

  • @santhosh1895
    @santhosh1895 2 роки тому

    Hi, Is there any difference in dropdown between Selenium 3 vs 4?

  • @user-bb4vr9gk3t
    @user-bb4vr9gk3t Місяць тому

    What is the next step? What to learn?

    • @RaghavPal
      @RaghavPal  Місяць тому

      Can check all Selenium tutorials here - automationstepbystep.com/

  • @sivakumark4958
    @sivakumark4958 2 роки тому

    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.

    • @RaghavPal
      @RaghavPal  2 роки тому +1

      You can if needed, can use tools like Applitools - ua-cam.com/video/ItutKRrq0JI/v-deo.html

    • @sivakumark4958
      @sivakumark4958 2 роки тому

      Thanks you so much.

    • @shashikantgaurav1689
      @shashikantgaurav1689 2 роки тому

      @@RaghavPal Thanks Raghav...for Your Selfless efforts.You are doing great work.please continue it

  • @ten2soft-wg9xh
    @ten2soft-wg9xh 11 місяців тому

    selectobject is showing a red line in my drop down

    • @RaghavPal
      @RaghavPal  11 місяців тому

      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

    • @ten2soft-wg9xh
      @ten2soft-wg9xh 11 місяців тому

      thank u my great friend....i love you@@RaghavPal

  • @ankitshukla5800
    @ankitshukla5800 2 місяці тому

    Why select why not .click() method?

    • @RaghavPal
      @RaghavPal  2 місяці тому +1

      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
      -

    • @ankitshukla5800
      @ankitshukla5800 2 місяці тому

      Thanks a lot ❤​@@RaghavPal

  • @yashgupta-qn6qg
    @yashgupta-qn6qg Рік тому

    hi sir can u please provide all source codes?

  • @antarapatil7491
    @antarapatil7491 2 роки тому

    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
      @RaghavPal  2 роки тому +1

      Hi Antara, check
      1. the element locators are correct
      2. add some wait
      3. check the element is not masked

    • @antarapatil7491
      @antarapatil7491 2 роки тому

      @@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

    • @RaghavPal
      @RaghavPal  2 роки тому

      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

    • @antarapatil7491
      @antarapatil7491 2 роки тому

      @@RaghavPal ok Thanks Raghav

  • @sathiksha3654
    @sathiksha3654 2 роки тому

    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

    • @RaghavPal
      @RaghavPal  2 роки тому

      HI Sathhik, you must be getting a caused by section in the logs, pls check

    • @sathiksha3654
      @sathiksha3654 2 роки тому

      @@RaghavPal Thanks Raghav,

    • @sathiksha3654
      @sathiksha3654 2 роки тому

      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

    • @pavang2827
      @pavang2827 2 роки тому

      @@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??

    • @RaghavPal
      @RaghavPal  2 роки тому

      I will check on this and update as I get some info