简体   繁体   English

如果按钮只有一个类,如何通过机器人框架单击

[英]How to click by robot framework if button is having only class

I need to click the button Calculate on the next webpage 我需要单击下一页上的计算按钮

https://www.seb.lv/eng/loan-and-leasing/leasing/leasing-calculator https://www.seb.lv/eng/loan-and-leasing/leasing/leasing-calculator

Button is having next code, as you could see it does not have id or name Button具有下一个代码,如您所见,它没有ID或名称

<button type="submit" class="btn btn-dark">Calculate</button>

Possibly, I have tried all different constructions according to the Robot framework tutorial, but still without any luck 可能,我已经根据机器人框架教程尝试了所有不同的构造,但仍然没有任何运气

Also I have tried to emulate the click with Javascript expression (which should be supported by Robot Framework) 我也尝试用Javascript表达式模拟点击(机器人框架应支持该表达式)

Execute Javascript    function getElementByXpath(path) {return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;}; 
     getElementByXpath("//*[@class='btn btn-dark']").click();

Still without any success, although this construction works in the browser console. 尽管此构造可在浏览器控制台中运行,但仍然没有任何成功。

Also: had tried this constructions in Firefox and Google Chrome Browsers as from some answers seen from here I was expecting that it could be some certain browser problem. 另外:从这里看到的一些答案中,我曾尝试在Firefox和Google Chrome浏览器中进行此构造,我希望这可能是某些浏览器问题。

This button is on a iframe. 此按钮位于iframe上。 you should switch to the iframe before trying to click. 您应该在尝试点击之前切换到iframe。

driver.switch_to_frame(driver.find_element_by_xpath("//*[@class='calculator-frame']"))
driver.find_element_by_xpath("//*[@class='btn btn-dark']").click()

select frame (SeleniumLibrary) should help: select frame (SeleniumLibrary)应该有助于:

select frame     css=.calculator-frame
click button     css=.btn-dark

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

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