Xpath with combination of Preceding-sibling and following-sibling

前端 未结 2 1507
不知归路
不知归路 2021-01-26 06:30

I am trying to read the values from this screen( Sections appears dynamically it can be more than one). We have to read each field like Local Radios, MAC Address, Version from G

相关标签:
2条回答
  • 2021-01-26 07:15

    Since you have tagged Robot Framework, i'll give a robot specific solution here:

    ${legal_key}=      Get Text    xpath://td[text()='Local Radios']
    ${legal_value}=    Get Text    xpath://td[text()='Local Radios']/following-sibling::td
    

    Similarly for all the other fields you want.

    0 讨论(0)
  • 2021-01-26 07:19

    To retrieve each field like Local Radios, MAC Address, Version from General Application Statistic and the field Default Geo Code from Legacy Configuration you can use the following code block :

    List<WebElement> all_items1 = driver.findElements(By.xpath("//table[@class='tabletext']/tbody//tr//td//table//tbody//tr//td[contains(.,'General Application Statistics')]//following::td"));
    List<String> properties = new ArrayList<String>(3);
    List<String> values = new ArrayList<String>(3);
    for (int i=0;i<all_items.size();i=i+2)
        properties.add(all_items.get(i).getAttribute("innerHTML"));
    for (int j=1;j<all_items.size();j=j+2)
        values.add(all_items.get(j).getAttribute("innerHTML"));
    for (int k=0;k<properties.size();k++)
        System.out.println("Property " + properties.get(k) + " has a value of " + values.get(k));
    List<WebElement> all_items2 = driver.findElements(By.xpath("//table[@class='tabletext']/tbody//tr//td//table//tbody//tr//td[contains(.,'Legacy Configuration')]//following::td"));
    List<String> properties = new ArrayList<String>(1);
    List<String> values = new ArrayList<String>(1);
    for (int i=0;i<all_items.size();i=i+2)
        properties.add(all_items.get(i).getAttribute("innerHTML"));
    for (int j=1;j<all_items.size();j=j+2)
        values.add(all_items.get(j).getAttribute("innerHTML"));
    for (int k=0;k<properties.size();k++)
        System.out.println("Property " + properties.get(k) + " has a value of " + values.get(k));
    
    0 讨论(0)
提交回复
热议问题