如何使用selenium在网页上选择子节点值

时间:2018-02-12 11:57:57

标签: selenium-webdriver

这是我需要自动化的网页。复选框旁边的值是动态的。他们不是一成不变的。所以我想选择其中一个选项,当我点击搜索按钮时,将显示匹配的搜索结果。请帮忙。

HTML DOM Code and Screen which needs to be automated

Bigger version

3 个答案:

答案 0 :(得分:0)

我不是xpath的粉丝,但我认为这是你最好的选择。 请尝试以下方法:

收集手风琴下的所有跨度,如下所示:

List<WebElement> elements = driver.findElements(By.xpath("//div[@class='rms-accordion-content']/label/span")

然后遍历列表并使用数据绑定属性文本过滤掉所有元素:名称

希望这会有所帮助。 祝你好运!

答案 1 :(得分:0)

driver.findElements(By.xpath(&#34; // DIV [@class =&#39;均方根手风琴式内容&#39;] /标签/跨度&#34)); Iterator i = elements.iterator(); while(i.hasNext()){WebElement row = i.next();的System.out.println(row.getText()); }

这是我用的

答案 2 :(得分:-1)

下面的代码将显示所有复选框名称 注意:代码在C#中

-- Create table with 93 strings of different lengths, plus one NULL string. Notice the only ASCII character not used is '!', so I will use it as a delimiter in LISTAGG.
create table strings as 
with letters as ( 
  select level num, 
  chr(ascii('!')+level) let 
  from dual 
  connect by level <= 126 - ascii('!') 
  union all 
  select 1, null from dual 
) 
select rpad(let,num,let) str from letters;

-- Note the use of LENGTHB to get the length in bytes, not characters.
  select str,   
  sum(lengthb(str)+1) over(order by str rows unbounded preceding) - 1 cumul_lengthb,   
  sum(lengthb(str)+1) over() - 1 total_lengthb,   
  count(*) over() num_values   
  from strings   
  where str is not null;

-- This statement implements the ON OVERFLOW TRUNCATE WITH COUNT option of LISTAGG in 12.2. If there is no overflow, the result is the same as a normal LISTAGG.
select listagg(str, '!') within group(order by str) || 
  case when max(total_lengthb) > 4000 then 
    '! ... (' || (max(num_values) - count(*)) || ')' 
  end str_list 
from ( 
  select str, 
  sum(lengthb(str)+1) over(order by str) - 1 cumul_lengthb, 
  sum(lengthb(str)+1) over() - 1 total_lengthb, 
  count(*) over() num_values 
  from strings 
  where str is not null 
) 
where total_lengthb <= 4000 
   or cumul_lengthb <= 4000 - length('! ... (' || num_values || ')');