尝试使用 Webdriver 通过 linkText 查找链接时,有没有办法忽略大写? [英] Is there a way to ignore upper case when trying to find a link by linkText with Webdriver?

查看:27
本文介绍了尝试使用 Webdriver 通过 linkText 查找链接时,有没有办法忽略大写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Selenium 2 Webdriver.

I am using Selenium 2 Webdriver.

我想点击一个链接,但链接文本可以是Linktext"或LINKTEXT".还有比这更好的方法吗:

I want to click on a link but the link text can be "Linktext" or "LINKTEXT". Is ther a better way than that:

List<WebElement> list = driver.findElements(By.linkText("Linktext"));
if(list.size()>0){
    driver.findElement(By.linkText("Linktext")).click();
} else {
    driver.findElement(By.linkText("LINKTEXT")).click();
}

API 和谷歌并没有真正帮助我.任何想法如何忽略大写?

API and google didnt really help me. Any ideas how to ignore upper case?

推荐答案

我也一直在努力解决这个问题.我还没有解决它,但这里是我的概念的草稿.看起来它会起作用,但它不起作用(我收到了一个陈旧的引用异常).我只需要弄清楚如何让这种事情发挥作用:

I've also been trying to figure this one out. I haven't solved it yet, but here is the rough draft of my concept. It looks like it will work but it doesn't ( I get a stale reference exception) . I just need to figure out how to get this kind of thing working :

public boolean clickByLinkTextInsensitive( String matcher ) {
    List<WebElement> els = driver.getElements( By.xpath( ".//a[@href!='']" ) );
    for ( WebElement el: els ) {
        if ( els.getText().toLowerCase().equals( matcher.toLowerCase() ) ) {
           el.click();
        }
    }
}

这篇关于尝试使用 Webdriver 通过 linkText 查找链接时,有没有办法忽略大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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