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

thi*_*ran 3 html javascript java selenium xpath

<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>
Run Code Online (Sandbox Code Playgroud)

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

我怎样才能得到那个元素?我正在使用Java。
我尝试通过 id cont逐步获取 -> 通过 id fscont -> 通过名称获取 cboxform但我不能再去,卡在这里。

WebElement inputName = driver.findElement(By.id("cont"));
inputName = inputName.findElement(By.id("fscont"));
inputName = inputName.findElement(By.name("cboxform"));
Run Code Online (Sandbox Code Playgroud)

非常感谢。

ale*_*cxe 5

所需的元素在 a 内iframe,您需要在进行搜索之前切换到它

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

driver.findElement(By.id("tblmid"));
Run Code Online (Sandbox Code Playgroud)

也可以看看: