4
<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>

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.

thienkhoi tran
  • 341
  • 2
  • 9

2 Answers2

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:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
0

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 components 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.

Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153