Perform Scroll Operations using JavascriptExecutor in Selenium WebDriver

Поделиться
HTML-код
  • Опубликовано: 7 янв 2025

Комментарии • 28

  • @HYRTutorials
    @HYRTutorials  4 года назад +1

    📌 JavascriptExecutor Playlist Link: bit.ly/2FhNXwS
    ✴ Checkout my other playlists: bit.ly/3gLIAVL
    ☕ Buy me a coffee: bit.ly/33ljBWc

  • @kirandvn8953
    @kirandvn8953 3 года назад +2

    Very well explained. I wish you do more videos for the testing community. All the best!!!

  • @angaraki
    @angaraki 4 года назад +1

    Wonderful!!! Thank you. Header menu Vs Sticky menu - nice example!

  • @bharathij2893
    @bharathij2893 2 года назад +1

    Such a very useful video and I learned a new stuff today... thanks a lot

  • @dbvs007
    @dbvs007 2 года назад +1

    Nicely done!! Great job!!!

  • @ChiragBhatt-w5s
    @ChiragBhatt-w5s Год назад +1

    Thank You Sir!

  • @bsk8643
    @bsk8643 3 года назад +2

    Thank you so much. This is very helpful
    I would also love to see how to scroll inside angular grid using javasript.
    Angular gird uses virtual dom elements .
    Please refer angular grid demo from angular official site
    I will wait for your video 🥰

    • @HYRTutorials
      @HYRTutorials  3 года назад

      I didnt find any grid example in angular official website

    • @bsk8643
      @bsk8643 3 года назад

      @@HYRTutorials I learned so much from your videos. Thank you so much for sharing knowledge.

    • @bsk8643
      @bsk8643 3 года назад

      @@HYRTutorials www.ag-grid.com/example.php
      In this example you can see columns are visible in dom only when we scroll inside the grid and this is same for both horizontal and vertical scroll
      Please do a video on this . 🙏

    • @bsk8643
      @bsk8643 3 года назад

      @@HYRTutorials brother any update please?

    • @bsk8643
      @bsk8643 3 года назад

      @@HYRTutorials can you do a video on what I was looking for ?
      That will help thousands of people...

  • @anshuv585
    @anshuv585 3 года назад +1

    Thank you for explanation, can we drag a element by co-ordinates using JavaScriptExecutor like dragAndDropBy() method in actions class

    • @HYRTutorials
      @HYRTutorials  3 года назад

      Thankyou 😊
      I have never tried it but if we can do it using javascript then you can do it from jsexecutor also.

    • @anshuv585
      @anshuv585 3 года назад +1

      @@HYRTutorials Thank you

  • @swapnabhaskaruni9652
    @swapnabhaskaruni9652 2 года назад

    I have 4 div elements and in one of the div i can scroll horizontally and then it loads new elements into DOM. if i do not scroll the elements are not even present in DOM. I tried this
    js.executeScript("document.querySelector(\"div[style$='box-sizing: border-box; direction: ltr; height: 521px; position: absolute; width: 1311px; will-change: transform; overflow: auto hidden; left: 365px; border-left: 1px solid rgb(235, 235, 235);']\").scrollLeft = 1500;");
    but not getting the effect i want.
    Do you have any idea on how to scroll to elements that are not even in DOM

    • @HYRTutorials
      @HYRTutorials  2 года назад

      No buddy but you can scroll based on some random values like 500 or 1000 and see if it works.

  • @guddukumarilokesh3979
    @guddukumarilokesh3979 2 года назад

    hi sir, can u tell me how to use browser.executeScript() for clicking the element in webdriverio.

    • @HYRTutorials
      @HYRTutorials  2 года назад

      I haven't created any videos on webdriverio buddy

  • @praveenjaldawar2652
    @praveenjaldawar2652 3 года назад +1

    Hello Sir,
    Assume a page contain a button at the bottom of page, after clicking on that button page will scroll down. I don't know how many times it displays the button when i scroll down page. Here below the code for your reference
    WebElement viewMore = driver.findElement(By.xpath("//div[@id='listFetchMore']"));
    JavascriptExecutor js = (JavascriptExecutor) driver;

    js.executeScript("arguments[0].scrollIntoView(true);", viewMore);
    viewMore.click();

    js.executeScript("arguments[0].scrollIntoView();", viewMore);

    viewMore.click();

    js.executeScript("arguments[0].scrollIntoView();", viewMore);

    viewMore.click();
    List allRows = driver.findElements(By.xpath(or.getProperty("XTableRows")));
    System.out.println("Number of rows in the table " + allRows.size());
    In Above code, i written 3 times statement i.e scrollIntoView and click method. Guide, how to write a condition so that loop will execute until that element is visible.

    • @HYRTutorials
      @HYRTutorials  3 года назад

      You can achieve this in multiple ways.
      1. Try to use the try catch while finding that button. When it throws the exception break the loop.
      2. Try using findelements method to get the count of that button and if it returns zero then break the loop