我有一个Web类型的应用程序,其中包含<bean:define>
标签。我正在寻找一种解决方案来通过 firepath
识别此标签XPath
创作。
当我挖掘与此标签相关的信息时,我发现它被用在Struts
中根据 id 和 value 参数设置范围。此外,没有发生与此标签相关的讨论。
下面提到的网页结构:
<bean:define id="loggedInUserUserName" name="loggedInUser" property="firstName">
<iframe id="frame_admin_console" class="noautowidth" name="sample_1" rel="col1" scrolling="auto" t_src="scriptPath" style="visibility: visible; height: 861px; width: 1608px;" src="srcPath=" height="iframe_height" frameborder="0" width="100%">
我试图找到iframe
通过创建 Xpath
的
.//*bean:define[@id='loggedInUserUserName']/./iframe[@id='frame_admin_console']
但这并没有给我一个有效的 xpath
在firebug
。
有什么办法可以找到DOM
<bean:define>
的元素通过创建 XPATH
来输入在 Selenium Web 驱动程序中?
最佳答案
Is there any way I can locate DOM elements of bean:define type by creating 'XPATH' in selenium web driver?
您可以使用 name()
来定位具有此类标签名称的元素。 xpath
的函数用于识别如下:-
//*[name() = 'bean:define']
或更具体
//*[name() = 'bean:define' and @id = 'loggedInUserUserName']
I have tried to locate iframe by creating an Xpath of .//*bean:define[@id='loggedInUserUserName']/./iframe[@id='frame_admin_console'], but this didn't give me a valid xpath in firebug.
然后按如下方式使用:-
//*[name() = 'bean:define' and @id = 'loggedInUserUserName']//iframe[@id='frame_admin_console']
引用: name(node-set?)返回作为参数传递的节点集或当前节点集中的当前节点的完整文本节点名称
这对于信息目的很有用。但是,如果您的目标是切换到 iframe
,您可以简单地使用它的 id 属性值(如果 id 属性值是唯一的)切换该 iframe
,如下所示(假设您使用的是 java ):-
driver.switchTo().frame("frame_admin_console");
关于Selenium xpath - 使用 <bean :define> tag name 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41219565/