如何使用硒选择镜架? [英] How to select a frame using selenium?

查看:71
本文介绍了如何使用硒选择镜架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java创建硒测试用例.我的系统基于相互连接的Portlet.我正在使用"selectFrame"命令来选择portlet.

I'm using Java to create selenium test cases. My system is based on portlets connected to each other. I'm using "selectFrame" command to select the portlet.

我尝试了很多事情,但似乎无法像这样工作:

I tried many things but it seems it is not working like this:

driver.switchTo().frame("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]");

driver.findElement(By.id("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]"));

有人可以帮助我吗?

推荐答案

您有一个XPath表达式,该表达式应该可以为您提供所需的IFrame元素.但是,您没有告诉Selenium这是一个XPath表达式.以下是您需要的:

You have an XPath expression that is supposed to get you the IFrame element you need. However you are not telling Selenium it's an XPath expression. The below is what you need:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]"));

请注意,我的Java不是最好的,所以这可能会导致编译问题,但是您应该了解一下.

Note, my Java is not it's best, so this may cause compilation issues but you should see the idea.

首先找到元素,方法是告诉Selenium它是您提供的XPath表达式,然后使用该元素并将其粘贴在切换到框架"表达式中.

Find the element first, by telling Selenium it's an XPath expression you are giving it, then use that element and stick it right in the 'switch to frame' expression.

这篇关于如何使用硒选择镜架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆