在 Selenium 中单击时 Twitter 引导模式按钮不起作用 [英] Twitter bootstrap modal buttons not working when clicked in Selenium
问题描述
我想知道是否有其他人遇到过这个问题.我有一个使用 twitter bootstrap 的网站,在我的脚本中,我打开了一个模态,我浏览并与该模态中的几个对象(文本输入、下拉菜单、复选框)进行了良好的交互.但是当我最后点击提交按钮时,什么也没有发生.
I'm wondering if anyone else has experienced this issue. I've got a website utilising twitter bootstrap, at one point in my script I open a modal, I go through and interact fine with several objects within that modal (text input, dropdown, checkbox). But when I come to clicking the submit button at the end nothing happens.
就硒而言,它点击了它,如果我在它运行时观看屏幕并且可以看到按钮高亮显示,就像点击一样,但没有任何反应.如果我之后尝试单击它,除了按钮突出显示之外,仍然没有任何反应.如果我然后按 RETURN 或 ENTER 然后它会很好地触发...
As far as selenium is concerned it clicked it, and if I watch the screen while its running and could see the button highlight as if clicked, but nothing happens. If I then try to click on it afterwards still nothing happens other than the button highlights. If I then hit RETURN or ENTER then it fires fine...
我尝试过而不是点击发送 ENTER 或 RETURN 但他们都做同样的事情并且完全不知所措,我通过 XPATH 识别对象,据我所知看起来是正确的......
I've tried instead of clicking sending ENTER or RETURN but they all do the same thing and am at a complete loss, I identify the object via XPATH which as far as I can see looks right...
这是代码的一部分,请记住,在此之前的一切都有效...
Here's a chunk out of the code, bear in mind that everything before this works...
threadSesh.driver.findElement(By.xpath(".//*[@id='createDeal']").click();
threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[1]/input").clear();
threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[1]/input").sendKeys("MyNewProject");
Select myDropDown = new Select(threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[3]/select")));
myDropDown.selectByVisibleText("Buy Out");
threadSesh.driver.findElement(By.xpath(".//*[@id='ProjectOriginator']/li/input").click();
threadSesh.driver.findElement(By.xpath(".//*[@id='ProjectOriginator']/li/input").sendKeys("John smith");
threadSesh.driver.findElement(By.xpath("(//a[contains(text(),'Create')])[2]").click();
它的最后一行什么都不做......任何建议将不胜感激!
Its the final line that just does nothing... Any suggestions would be very much appreciated!
另外值得指出的是,我正在使用 ie 并且无法在 chrome 或 FF 中测试它(我正在测试的这个网站上不允许有任何版本,它是一个内部平台).
Also worth pointing out I am using ie and cannot test this in chrome or FF (neither version is allowed on this website I'm testing, its an internal platform).
另一条可能有用的信息,按钮实际上不是按钮,而是某种类型的引用,使用 twitter bootstrap 的东西看起来像一个按钮,它的来源如下所示:->
Another piece of potentially useful information, the button isn't a button in fact but a ref of some kind that's been made to look like a button using the twitter bootstrap stuff, the source for it looks like this: -
<a class="btn btn-small btn-info" type="button" style="margin-right: 7px; padding-left: 15px; padding-right: 15px;" data-bind="click: ok" href="#">Create</a>
如果我将它记录在 Firefox 的硒插件中,它会输出:-
If I record it in the seleneium addin for firefox it outputs this: -
driver.findElement(By.xpath("(//a[contains(text(),'Create')])[2]")).click();
推荐答案
我设法想出了一个解决方案,但完全靠运气.基本上在我点击取消或创建链接之前,我正在与一些 tagit 输入进行交互,并且不得不做一些摆弄以使它们工作.
I managed to come up with a solution to this, only by sheer luck though. Basically before I click on the Cancel or Create links I was interacting with some tagit inputs and had to do some fiddling to get them to work.
这些标签在模态的一个 div (html/body/div[3]/div[2]
) 中,链接在另一个 (html/body/div[3]/div[3]
) 而这种摆弄似乎以某种方式阻止了 Selenium 看到另一个 div,尽管我不确定如何.
These tagits were in one div (html/body/div[3]/div[2]
) within the modal and the links were in another (html/body/div[3]/div[3]
) and this fiddling around seemed to have stopped Selenium from seeing the other div somehow, although I'm not sure how.
为了解决这个问题,我只需点击顶层的模式 (html/body/div[3]
),然后它发现较低级别的链接很好!我不知道这是如何解决的,但至少我的脚本现在又可以正常工作了...
To fix the issue I simply added in a click of the modal at the top level (html/body/div[3]
) and then it found the lower level links fine! How this fixes it I don't know but at least my scripts work fine again now...
这篇关于在 Selenium 中单击时 Twitter 引导模式按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!