Selenium WebDriver findElement(By.xpath()) 对我不起作用 [英] Selenium WebDriver findElement(By.xpath()) not working for me

查看:39
本文介绍了Selenium WebDriver findElement(By.xpath()) 对我不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了 xpath 教程并查看了许多其他帖子,因此我不确定我错过了什么.我只是想通过 xpath 找到以下元素:

I've been through the xpath tutorials and checked many other posts, hence I'm not sure what I'm missing. I'm simply trying to find the following element by xpath:

<input class="t-TextBox" type="email" test-id="test-username"/>

我尝试了很多东西,例如:

I've tried many things, such as:

element = findElement(By.xpath("//[@test-id='test-username']"));

错误是Expression is not a legal expression.

我在 MacBook 上使用 Firefox

I'm using Firefox on MacBook

任何建议将不胜感激.

推荐答案

element = findElement(By.xpath("//*[@test-id='test-username']"));
element = findElement(By.xpath("//input[@test-id='test-username']"));

(*) - 表示任何标签名称.

(*) - means any tag name.

这篇关于Selenium WebDriver findElement(By.xpath()) 对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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