.ajax can t find,ajax - Selenium webdriver can't find button - Stack Overflow

博主在尝试使用WebDriver自动化测试时遇到了一个棘手的问题:无法通过ID或XPath定位并点击一个特定的‘Apply’按钮。尽管该元素在IDE中可以被找到,但在WebDriver中始终报错‘Unable to locate element’。已经尝试了直接点击、JavaScript执行点击以及等待页面加载等方法,但均未成功。问题可能出在动态加载的元素或者页面结构的复杂性上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

EDIT:

I have cleaned this up a bit.

I have a button that looks like this:

value="Apply" οnclick="wicketShow('applyRuleButton--ajax-indicator');var

wcall=wicketSubmitFormById('id256', '?wicket:interface=:23:form:filtersContainer:applyRuleButton:

:IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true',

'filtersContainer:applyRuleButton' ,function() { ;wicketHide('applyRuleButton--

ajax-indicator');}.bind(this),function() { ;wicketHide('applyRuleButton--

ajax-indicator');}.bind(this), function() {return

Wicket.$$(this)&&Wicket.$$('id256')}.bind(this));;; return false;" type="submit">

Firebug:

οnclick="wicketShow('applyRuleButton--ajax-indicator');var

wcall=wicketSubmitFormById('id2ee',

'?wicket:interface=:29:form:filtersContainer:applyRuleButton::IActivePageBehaviorListener:0

:&wicket:ignoreIfNotActive=true', 'filtersContainer:applyRuleButton' ,function() {

;wicketHide('applyRuleButton--ajax-indicator');}.bind(this),function() {

;wicketHide('applyRuleButton--ajax-indicator');}.bind(this), function() {return

Wicket.$$(this)&&Wicket.$$('id2ee')}.bind(this));;; return false;" value="Apply"

name="filtersContainer:applyRuleButton">

I'm trying to click it and have tried pretty much everything for 2 days, webdriver does not find the element, IDE does find it:

//This was my first approach, it should work.

It works in IDE, but not Webdriver:

driver.findElement(By.id("applyRuleButton")).click();

//then perhaps this should do the trick, hint: It doesn't:

WebElement element3 = driver.findElement(By.id("applyRuleButton"));

JavascriptExecutor executor3 = (JavascriptExecutor)driver;

executor3.executeScript("arguments[0].click();", element3);

Ok, Id not working, I get it.

Then this should work at least:

driver.findElement(By.xpath("//table/tbody/tr/td/div/div/table/tbody/tr[6]/td/input[@id='applyRuleButton']")).click();

It feels like I am missing something obvious here, some help please?

Additional information:

I have added a 5 second wait, the page is completely loaded.

This button is located in a table:

OPvE2.png

The Xpath is

/html/body/div[4]/div[2]/form/div[3]/div/div/table/tbody/tr/td/div/div/table/tbody/tr[6]/td/input

Webdriver error, no matter what I throw at it, is: Unable to locate element

I have used both 'click' and 'submit', still no success.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值