简体   繁体   中英

Selenium Webdriver can't find table elements

I'm new with selenium, I can not figure out how to find some elements from an HTML page. I reproduced the page here :

http://www.ladiana.it/test/test.htm

I need to click on this button : Selection and after the table appears, to read and write their values :

values

I'm using c# and I tried all possible way, I also tried to list all the elements with the Id : "targetDemandReductionMW"

IList IWebElement> all = driver2.FindElements(By.Id("targetDemandReductionMW"));

I get a list of 52 void elements.

Here some other code , it doesn't generate any error but didn't work:

 IWebElement element_xpath = driver2.FindElement(By.ClassName("tab_buttonSel"));
        element_xpath.Click();
        IWebElement table = driver2.FindElement(By.Id("drr1OfferAM"));
        
       
          var rows = table.FindElements(By.TagName("tr"));


       
        int conteggio = 0;
            foreach (var row in rows)
           {
                var rowTds = row.FindElements(By.TagName("td"));
                foreach (var td in rowTds)
                {
                    IWebElement a = td.FindElement(By.XPath("//*[@id='targetDemandReductionMW']"));
                Console.WriteLine(conteggio++.ToString()+" "+a.GetAttribute("href")+" "+ a.Text);
                
                     

                }
            }

Any help? Thanks

For the button you need to click, you can use:

//div[@id='tabContainer']/div[2]/following::tr/td[text()='DRR1 Offer']

For the xpath for the table records you can use:

//table[@id='drr1OfferPMHead']//td[@id='targetDemandReductionMW']

This returns the 13 rows that you are looking for. You can then do FindElements on this and get a list.

           List<String> search = new List<string>();
        IReadOnlyList<IWebElement> cells = driver.FindElements(By.Xpath("//table[@id='drr1OfferPMHead']//td[@id='targetDemandReductionMW']"));
        foreach (IWebElement cell in cells)
        {
            search.Add(cell.Text);
            
        }

The cell (in the html) has cellclick event , but if i try with :

  foreach (IWebElement cell in cells)
        {
            search.Add(cell.Text);
            if (cell.Text=="300.0")
               {
                cell.click();   
               }


        }

it come out this error : "OpenQA.Selenium.ElementNotInteractableException: 'element not interactable"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM