如何使用Java获取Selenium WebDriver的父HTML标记 [英] How do I get an parent HTML Tag with Selenium WebDriver using Java

查看:427
本文介绍了如何使用Java获取Selenium WebDriver的父HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试,搜索< span class =legend> 。在以前的级别上,我有一个包含多个值的字段集。这是我的问题。我没有获得此字段集的定位器。

I have a Test which search for <span class="legend">. On a previous level I have a fieldset which contains several values. Here is my problem. I don't get the locator for this fieldset.

首先,我得到一个包含所有 class = legend 对象的列表:

First of all I get a list with all class=legend objects:

列表< WebElement> groupList = driver.findElements(By.className(legend));

这完美无缺,我有一个包含多个Webelements的列表。

This works perfectly, I have a list with several Webelements.

现在我想迭代这个列表,只保存上一级字段集中的每个值。问题是Selenium找不到fieldset的id。

Now I want to iterate this list and save every value from the fieldset of the previous level only. The problem is that Selenium does not find the id of the fieldset.

我试过 tempGroupElement.getAttribute(id)来获取id,但它不起作用。

I tried tempGroupElement.getAttribute("id") to get the id but it does not work.

有什么想法吗?

谢谢!

Any idea?
Thanks!

推荐答案

我在C#中有一个方法。

I have a method for this in C#.

public static IWebElement GetParent(IWebElement e)
{
   return e.FindElement(By.XPath(".."));
}

希望有所帮助:)

这篇关于如何使用Java获取Selenium WebDriver的父HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆