Home > Blockchain >  Selenium c# Ilist Iweb Element not getting the text of all elements
Selenium c# Ilist Iweb Element not getting the text of all elements

Time:09-06

im using IList to get a list of elements and the text value to be able to click on the correct element

IList<IWebElement> PONumbers = driver.FindElements(By.ClassName("first-column"));
        
        int POCount = PONumbers.Count;
        
        for (int i = 0; i < POCount; i  )
        { 
            String PONo = PONumbers.ElementAt(i).Text;
            
            if (PONo.Equals(PONoNonBatchNonTonne))
            {
                PONumbers.ElementAt(i).Click();
                break;
            }
        }

It gets all the correct elements which is 36

It only gets the text for the first 8 elements and then the rest are showing as ""

this is the html code:
this is the html code

it seems to be only getting the text of the elements in the view, but then why would it get all elements

any help welcome?

CodePudding user response:

Since the element is hidden on webpage you have to use textContent attribute to get the value. To click on the element either scroll the page or use javaScript executor to click on the specific element.

IList<IWebElement> PONumbers = driver.FindElements(By.ClassName("first-column"));
        
        int POCount = PONumbers.Count;
        
        for (int i = 0; i < POCount; i  )
        { 
            String PONo = PONumbers.ElementAt(i).GetAttribute("textContent");
            
            if (PONo.Equals(PONoNonBatchNonTonne))
            {
                IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
                executor.ExecuteScript("arguments[0].click();", PONumbers.ElementAt(i));                
                break;
            }
        }

CodePudding user response:

Selenium only gets the elements that are in the view.

Once you have the last element you should be able to select it, send it some keys another 8 times, arrow down usually,and get the next 8 elements.

This would be have to be done for each set of 8 until you get the last one.

The web is loading content dynamically through jsp or similar and selenium needs to manually access all of the content that is dynamically loaded.

In order to test my theory run your test and go back to the browser window, select the last element in the view and see which key selects the next element and moves the elements in the view.

  • Related