我正在尝试使用自动化一些测试用例。我点击一个按钮打开一个新窗口/iframe/弹出。它需要在文本框中添加一些数据,然后从拖放框中选择一些数据。我有两个问题,
这是当我选择新窗口/iframe/弹出(图像附件),html/body/div[11]
时在火路径中看到的xpath和内容。
我这里有密码,zenoss_url = "http://xxxxx/" xpath_uname = "html/body/form/div/div/input[1]" xpath_pwd = "html/body/form/div/div/input[2]" xpath_submitButton = "html/body/form/div/div/input[3]" xpath_eventsTab = "html/body/div[7]/div/div/div/div[2]/ul/li[2]/div/div/a" driver = webdriver.Firefox() driver.get(zenoss_url) handle = driver.find_element_by_xpath(xpath_uname) handle.send_keys(zenoss_uname) handle = driver.find_element_by_xpath(xpath_pwd) handle.send_keys(zenoss_pwd) driver.find_element_by_xpath(xpath_submitButton).submit() driver.implicitly_wait(10) driver.find_element_by_xpath("html/body/div[7]/div/div/div/div[2]/ul/li[2]/div/div/a").click() driver.find_element_by_xpath("html/body/div[3]/div/div/div/div[1]/div/div/div[1]/div/div/div[7]/em/button").click() driver.implicitly_wait(5) window = driver.switch_to_window(?????)
我不知道我该用什么“名字”来代替?
感谢你的帮助。
发布于 2014-02-20 21:02:00
html/body/div11 11的路径只是框架范围内的xpath。当导航到框架和子帧时,可以采取以下几种方法:从查找框架的索引到查找框架的名称。如果使用火路径检查框架内的元素,它只会为元素提供该框架的范围。框架就像彼此之间的盒子一样工作;为了进入第二个盒子,你必须打开第一个盒子,然后往里面看。
//In C#
driver.switchTo().Frame("FirstFrameFound");
//To close the box again and get back to the overall main box.
driver.switchTo().defaultContent();
如果你的第二帧是第一帧的子帧,你必须跳入第一帧,然后切换到第二帧,与内部元素交互。
//In C#
//Switch to the first frame
driver.switchTo().Frame("FirstFrameFound");
//Switch to the second frame
driver.SwitchTo().Frame("SecondFrame");
//Now look for your element that you wish to interact with.
driver.FindElement(By.XPath("//html/body/div[11]"));
//To close the box again and get back to the overall main box.
driver.switchTo().defaultContent();
请在这里查看这篇文章,以获得更多信息。
How to navigate a subframe inside a frameset using Selenium WebDriver?
如果您切换到一个窗口,也有多种方法。我喜欢的方法是这种方法:
//When dealing with new window and the parent.
//Switch to the last window that opened
driver.SwitchTo().Window(driver.WindowHandles.Last());
//Perform your actions
driver.Close();
//Switch back to the first window
driver.SwitchTo().Window(driver.WindowHandles.First());
https://stackoverflow.com/questions/21918821
复制相似问题