在 Selenium 2.9 中选择图像 [英] Select Image in Selenium 2.9
问题描述
我正在尝试使用 RSpec 来尝试在我实习的地方进行维护后周末的自动化测试.我正在使用 Selenium WebDriver 2.9.0 来获取骨架,然后添加个性化代码.我目前遇到的是试图让 WebDriver 单击一个图像,然后导航到正确的 HTML,但我目前无法这样做.这是我到目前为止所拥有的......
I'm trying to use RSpec to try and automate testing for post-maintenance weekends here where I'm interning at. I'm using Selenium WebDriver 2.9.0 to get a skelton going and then adding in personalized code. What I'm currently stuck on is trying to have the WebDriver click on an image that will then navigate to the correct HTML but I'm currently unable to do so. Here's what I have so far...
it "can go to Ultratime" do
@ie_driver.find_element(:link, "My Resources").click
wait.until { @ie_driver.execute_script("return document.readyState;") == "complete" }
sleep 3
wait.until { @ie_driver.find_element(:link_text => "Login").displayed?}
#test above line
puts "found Ultratime"
#this just finds the "Logout" button and clicks it
@ie_driver.find_element(:name, "ee").click
end
这是与我试图浏览的网站的上述按钮"相关的 html 代码:
here's the html code pertaining to the said "button" for the site that I'm trying to navigate through:
<body id="ultratime-insidend" class="ultratime ultratime-insidend ">
<p id="ultratime">
<a class="single" href="#">
<img alt="Ultratime" src="https://controller.nd.edu/stylesheets/images/logo2.gif"></img>
Login
</a>
任何帮助将不胜感激!
推荐答案
点击图片就像点击任何其他元素一样.如果您在定位图像时遇到问题,请给它 id
并使用 css 选择器,即
Clicking on image works just like clicking on any other element. If you have problem locating image, give it id
and use css selector i.e.
driver.find_element_by_css_selector("#yourimageid").click()
将焦点切换到框架,使用:
to switch focus to frame, use:
driver.switch_to.frame driver.find_element(..)
任何定位器都可以工作,如果你不能设置 ID,比如
Any locator should work, if you can't set ID, like
drive.switch_to.frame driver.find_element( :xpath, "//iframe" )
这篇关于在 Selenium 2.9 中选择图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!