select web 元素 selenium web 驱动程序如何在另一个 html 标签内使用 html 源代码
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 创建的聊天框页面,我想在此页面上添加 select 个元素。
我尝试了很多方法来 select 这个网站中的 id tblmid 但我做不到。
使用了很多方法,例如通过名称获取、查找 xpath 然后通过 xpath 获取、通过 css 查找并获取它们……但它没有用。
我怎样才能得到那个元素?
我正在使用 java。
我试过一步一步 get by id cont -> get by id fscont -> get by name cboxform 但我不能再去了,卡在这里了。
WebElement inputName = driver.findElement(By.id("cont"));
inputName = inputName.findElement(By.id("fscont"));
inputName = inputName.findElement(By.name("cboxform"));
非常感谢。
存在称为 cross-site scripting 的安全问题。基本上,为了防止恶意攻击,浏览器(显然还有 JVM 等其他环境)会阻止一个域上的脚本访问另一个域上的页面组件。如果您的脚本不在该域上 运行,则您无法访问 www4.cbox.ws 上的元素。基本上,除非您对该域上的脚本具有编辑权限,否则您不能 select 该域网页中的元素,即使它嵌入在您的页面中也是如此。
所需的元素在 iframe
中,您需要在进行搜索之前切换到它:
driver.switchTo().frame("cboxform");
driver.findElement(By.id("tblmid"));
另请参阅:
- How to switch between frames in Selenium WebDriver using Java
<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 创建的聊天框页面,我想在此页面上添加 select 个元素。
我尝试了很多方法来 select 这个网站中的 id tblmid 但我做不到。
使用了很多方法,例如通过名称获取、查找 xpath 然后通过 xpath 获取、通过 css 查找并获取它们……但它没有用。
我怎样才能得到那个元素?
我正在使用 java。
我试过一步一步 get by id cont -> get by id fscont -> get by name cboxform 但我不能再去了,卡在这里了。
WebElement inputName = driver.findElement(By.id("cont"));
inputName = inputName.findElement(By.id("fscont"));
inputName = inputName.findElement(By.name("cboxform"));
非常感谢。
存在称为 cross-site scripting 的安全问题。基本上,为了防止恶意攻击,浏览器(显然还有 JVM 等其他环境)会阻止一个域上的脚本访问另一个域上的页面组件。如果您的脚本不在该域上 运行,则您无法访问 www4.cbox.ws 上的元素。基本上,除非您对该域上的脚本具有编辑权限,否则您不能 select 该域网页中的元素,即使它嵌入在您的页面中也是如此。
所需的元素在 iframe
中,您需要在进行搜索之前切换到它:
driver.switchTo().frame("cboxform");
driver.findElement(By.id("tblmid"));
另请参阅:
- How to switch between frames in Selenium WebDriver using Java