繁体   English   中英

Selenium webdriver无法找到我的按钮

[英]Selenium webdriver can't find my button

这是我的按钮链接:

<a class="button" href="#" onclick="ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')+'','keyboard')</a>"

而且我已经尝试过了

driver.findElement(By.xpath("//a[@class='ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')]"));

为什么selenium仍然找不到我指定的按钮?

它应该通过onclick访问,而不是一class简单的方法,

driver.findElement(By.xpath("//a[contains(@onclick, 'onClickValue')]");

我不知道你的HTML结构,但是

你有几个按钮?

如果您只有一个按钮,则不需要xpath,请使用更简单的方法:

driver.findElement(By.className("button"));

如果还有几个按钮,但您描述的按钮是唯一包含例如单词“terminallane”的按钮:

driver.findElement(By.xpath("//a[@class = 'button' and contains(@onclick, 'terminallane')]"));

尝试使用以下xpath ::

//a[@href='#']

其他

//a[contains(@onclick, 'ajaxtoelement('include/system.php?mode=begin&amp;location='+getSelectedValue('location')+'&amp;terminallane='+getSelectedValue('terminallane')+'','keyboard')')]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM