java - How can select web element selenium web driver with html source inside another html tag - Stack Overflow

<html><head><head><body><div id="title"><div><div

<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" autoplete="off" spellcheck="false" name="nme" maxlength="25" style="box-sizing: content-box; width: 301px;"></input>

I have a chatbox page, which was created by cbox.ws and I want to select elements on this page.
I tried many ways to select the id tblmid in this web but I can't.
Many ways was used such as get by name, find xpath then get by xpath, find and get them by css... but it didn't work.

How can I get that element? I am using java.
I tried get step by step get by id cont -> get by id fscont -> get by name cboxform but I can't go anymore, stuck here.

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

Thanks a lot.

<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" autoplete="off" spellcheck="false" name="nme" maxlength="25" style="box-sizing: content-box; width: 301px;"></input>

I have a chatbox page, which was created by cbox.ws and I want to select elements on this page.
I tried many ways to select the id tblmid in this web but I can't.
Many ways was used such as get by name, find xpath then get by xpath, find and get them by css... but it didn't work.

How can I get that element? I am using java.
I tried get step by step get by id cont -> get by id fscont -> get by name cboxform but I can't go anymore, stuck here.

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

Thanks a lot.

Share Improve this question edited Mar 24, 2015 at 3:04 thienkhoi tran asked Mar 24, 2015 at 3:00 thienkhoi tranthienkhoi tran 3412 silver badges9 bronze badges 2
  • I have added the code, could you help me to review this problem? – thienkhoi tran Commented Mar 24, 2015 at 3:05
  • If this is Java then you need to remove JavaScript. They're not the same. – Patrick Roberts Commented Mar 24, 2015 at 3:10
Add a ment  | 

2 Answers 2

Reset to default 5

The desired element is inside an iframe, you need to switch to it before making a search:

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

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

See also:

  • How to switch between frames in Selenium WebDriver using Java

There is a security issue referred to as cross-site scripting. Basically, to prevent malicious attacks, browsers (and apparently other environments such as JVM) prevent a script on one domain from accessing ponents of a page on another domain. You can't access an element on www4.cbox.ws if your script isn't also running on that domain. Basically unless you have editing access to scripts on that domain, you can't select an element within a webpage on that domain, even if it is embedded in your page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745378304a4625104.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信