43467

How to handle div that is created dynamically in a table

Question:

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/pNZrm.png" data-original="https://i.stack.imgur.com/pNZrm.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />I am trying to iterate a table to get the results. The structure of the table looks as mentioned in the picture

When I open the page, there is only one with role="presentation" and I am able to retrieve the data using the below css locator.

driver.findElement(By.cssSelector("div[id^=dojox_grid__View_] div.dojoxGridContent div.dojoxGridRow:nth-child(1) tbody tr:nth-child(1) td:nth-child(6)")).getText();

When I scroll the page manually another tag is created dynamically with role="presentation" and has many rows(div.dojoxGridRow). I want to iterate these rows too.

Selenium is able to go only to first level (first ) and get the details. I am not sure how to reach the second level

Answer1:

I'm not sure about which element you're trying to access.<br /> But you can access to all div with 'presentation' role (return a list):

driver.findElements(By.cssSelector("div[role='presentation']"));

If you're trying to access to each row under div with role presentation:

driver.findElements(By.cssSelector(".dojoxGridRow"));

If you want to get rows child of div with role 'presentation':

List<WebElement> presentations = driver.findElements(By.cssSelector("div[role='presentation']")); for (WebElement presentation : presentations) { List<WebElement> rows = presentation.findElements(By.cssSelector(".dojoxGridRow")); // DO SOMETHING... }

Hope that helps.

Recommend

  • SwiftUI Hide TabView bar inside NavigationLink views
  • Integrating search on a website where the backend is MYSQL
  • `for_each` not working as I expect
  • How to execute a stored procedure multiple times
  • WinDbg: APPLICATION_HANG_WRONG_SYMBOLS
  • Find the coefficients of the polynomial given its roots
  • Parallelizing C++ code using OpenMP, calculations actually slower in parallel
  • Fixed marker size at the android Google map
  • Codeigniter Where clause
  • Change PostgreSQL password encryption from MD5 to SHA
  • Why is my width at 100%?
  • Cannot intercept outgoing AJAX request from page using Testcafe
  • How do I determine if a DIB is bottom-up or top-down?
  • Is there anyway to bold certain regions of imagesc in MATLAB?
  • Sizing a UIPickerView inside a UIAlertView
  • SELECT sub-query with WHERE condition in Yii2 find() / QueryBuilder
  • Why is there a build.gradle and a build.sbt in play framework?
  • Can I detect change in text fields in SWT?
  • Building docker on yocto
  • How to Backup and Restore a MySQL Database using NetBeans?
  • Installing tf-nightly-gpu-2.0-preview on Google Colab
  • kube-apiserver high CPU and requests
  • OWL Api, move class from parent A to B
  • -(void)viewWillAppear:(BOOL)animated doesn't called
  • Simple Donut Chart with Raphael
  • How to add tag during runtime in C#
  • Preloading webView doesn't work - trying to reduce loading time
  • Videos won't upload
  • Smarter Removing Unnecessary WhiteSpace CSV
  • In metro, get all inherited classes of an (abstract) class?
  • Defer unused CSS
  • Modifying native query cannot have named parameter bindings?
  • readmore button or show/hide for php
  • Calculate time from document
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • Functions by reference or by variable, which to use when?