【发布时间】:2016-09-07 15:22:19
【问题描述】:
我是 Selenium 和 WebDriver 的新手。 我有这个 HTML:
<input id="undefined-undefined-Jobsubject-5546" type="text" value="" data-test="testing-job-subject" style="padding: 0px; position: relative; width: 100%; border: medium none; outline: medium none; background-color: transparent; color: rgb(255, 255, 255); cursor: initial; font: inherit; height: 100%; box-sizing: border-box; margin-top: 14px;"/>
我有这个代码:
driver.findElement(By.xpath("//input[@data-test='testing-job-subject']"));
但错误是:
org.openqa.selenium.NoSuchElementException:无法定位元素://input[@data-test='testing-job-subject']
我也试过这个:
driver.findElement(By.xpath("//*[starts-with(@id,'undefined-undefined-Jobsubject')]"));
因为id中的数字是生成的,所以不能取By.id(....),但是同样的错误。 是的,我在代码中有超时,所以元素在页面上。
问题出在哪里?谢谢
【问题讨论】: