本文介绍了获取href值(WebDriver)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从href中获取值?

How do I get a value from href?

如下所示:

<div id="cont"><div class="bclass1" id="idOne">Test</div>

    <div id="testId"><a href="**NEED THIS VALUE AS STRING**">
    <img src="img1.png" class="clasOne" />
    </a>

</div>
</div>
</div>

我需要将该值作为字符串。

I need that value as string.

我试过这个:

String e = driverCE.findElement(By.xpath("//div[@id='testId']")).getAttribute("href");
            JOptionPane.showMessageDialog(null, e);

但只返回NULL值...

But just returns NULL value...

推荐答案

您已将元素指向'div'而非'a'

You have pointed your element to 'div' instead of 'a'

尝试以下代码

driverCE.findElement(By.xpath("//div[@id='testId']/a")).getAttribute("href");

这篇关于获取href值(WebDriver)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 05:43
查看更多