问题
Has anyone been successful with getting Selenium to issue a mouse click on an element which is not associated with input, i.e. plain text? I have tried using click() and click_at() methods, as well as fire_event(locator, event), where 'event' is 'onclick', or by using combination of 'onmousedown' and 'onmouseup' events. I have also tried preceding these events with an 'onmouseover' event. In my app, clicking on this 'plain text' triggers a call to a flash.swf routine. Thanks.
回答1:
Have you tried adapting a Mouse Listener? In case you are extending Selenium using Java, here is a quick tutorial.
回答2:
Have you tried fire_event(locator, 'click') instead of 'onclick'?
回答3:
Have you tried tweaking fire event? As you are mentioning it as plain text locator of this should be like //p[contains(text(),'yourtext')]
something like this. Try it once.
回答4:
A native .click()
event should work fine if your using Firefox 31.6.0 ESR
(not a later version), or if your using Chrome. Keep in mind that for any event where a physical mouse click is not working for you (for whatever reason), you can still call a JavascriptExecutor to click the element (which is referred to as a synthetic non-native Selenium event).
来源:https://stackoverflow.com/questions/5045006/using-selenium-to-click-on-non-input-or-non-control-elements