Selenium webdriver 黄瓜元';找不到页面ID-Ruby、Capybara、Selenium

Selenium webdriver 黄瓜元';找不到页面ID-Ruby、Capybara、Selenium,selenium-webdriver,cucumber,capybara,Selenium Webdriver,Cucumber,Capybara,我在这里遇到困难。我想让Cucumber在页面上找到这个元素ID。首先确认它的存在,然后点击它 <a id="ga_Vehicle alerts_Vehicle tax: Expired" href="/vehicles/fleetRecords?dol.expired=true&amp;filter=expired" class="alert-3-row" title="Vehicles with expired tax"></a>. 找不到该元素 我哪里做错

我在这里遇到困难。我想让Cucumber在页面上找到这个元素ID。首先确认它的存在,然后点击它

<a id="ga_Vehicle alerts_Vehicle tax: Expired" href="/vehicles/fleetRecords?dol.expired=true&amp;filter=expired" class="alert-3-row" title="Vehicles with expired tax"></a>.
找不到该元素

我哪里做错了


干杯

根据您的HTML代码片段,
href
属性的值为
id=“ga\U车辆警报\U车辆税:过期”
。您的定位器略有不同:
“a\u车辆警报\u车辆税:过期”

您的ID中不应包含空格。从这里开始:

ID和名称标记必须以字母([a-Za-z])开头,后面可以是任意数量的字母、数字([0-9])、连字符(“-”)、下划线(“)、冒号(:”)和句点(“.”)

空格不是ID中的有效字符,将彻底混淆任何dom解析器、jquery、CSS、selenium等。如果确实需要ID中的大量信息,则应将空格从ID中删除,并用下划线替换。如果使用ID存储有关HTML节点的元数据,我建议不要这样做

您可能想要的是添加一些东西,如车辆和警报车辆作为类

Then /^I can verify that expired hyperlink is present within the alert$/ do
find_by_id "a_Vehicle alerts_Vehicle tax: Expired"
end