繁体   English   中英

如何在另一个html标签中选择带有html源的Web元素硒Web驱动程序

[英]How can select web element selenium web driver with html source inside another html tag

<html>
<head></head>
<body>
    <div id="title"></div>
    <div id="credit"></div>
    <div id="btnFS"></div>
    <div id="cont">
        <div id="fscont">
        <div style="font-size: 0px; position: absolute; left: 0; right: 0; top: …w: auto; overflow-y: auto; -webkit-overflow-scrolling:touch;"></div>
        <div style="font-size: 0px; position: absolute; left: 0; right: 0; height: 75px; overflow: hidden; bottom: 0;">
            <iframe width="100%" height="100%" frameborder="0" name="cboxform" scrolling="no" marginwidth="0" marginheight="0" src="//www4.cbox.ws/box/?boxid=4255329&boxtag=ev9nj4&sec=form" allowtransparency="yes">
                #document
                    <!DOCTYPE html>
                    <html style="position: absolute; height: 100%; width: 100%; overflow: hidden; margin: 0px; padding: 0px;">
                        <head></head>
                        <body class="fmbdy" style="padding: 0px; margin: 0px;">
                            <form class="cfrm" onsubmit="return do_post();" method="post" action="./?boxid=4255329&boxtag=ev9nj4&sec=submit" target="cboxmain" name="cbox">
                                <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0" style="width: auto;">
                                <tbody>
                                <tr></tr>
                                <tr>
                                <td id="tblmid" valign="top" style="vertical-align: top; white-space: nowrap; font-size: 0;" colspan="2">
                                    <input type="hidden" value="" name="key"></input>
                                    <input class="frmtb" type="text" onblur="frmblur(this, 'name');" onfocus="frmfocus(this, 'name');" value="name" size="9" autocomplete="off" spellcheck="false" name="nme" maxlength="25" style="box-sizing: content-box; width: 301px;"></input>

我有一个聊天框页面,它是由cbox.ws创建的,我想在此页面上选择元素。
我尝试了多种方法在此网络中选择id tblmid ,但是我不能。
使用了很多方法,例如通过名称获取,找到xpath,然后通过xpath获取,通过CSS查找和获取它们……但是它没有用。

我如何获得该元素? 我正在使用Java。
我试着一步一步地按ID继续->按ID fscont->按名称cboxform进行获取,但我不能再继续了,卡在这里。

WebElement inputName = driver.findElement(By.id("cont"));
inputName = inputName.findElement(By.id("fscont"));
inputName = inputName.findElement(By.name("cboxform"));

非常感谢。

所需元素在iframe ,需要进行搜索之前切换到该元素:

driver.switchTo().frame("cboxform");

driver.findElement(By.id("tblmid"));

也可以看看:

存在一个称为跨站点脚本的安全问题。 基本上,为了防止恶意攻击,浏览器(显然还有其他环境,例如JVM)阻止一个域上的脚本访问另一域上页面的组件。 如果您的脚本也未在该域上运行,则无法访问www4.cbox.ws上的元素。 基本上,除非您具有对该域上脚本的编辑权限,否则即使该元素已嵌入到页面中,也无法在该域上的网页中选择元素。

暂无
暂无

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

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