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.

2
  • I have added the code, could you help me to review this problem? Commented Mar 24, 2015 at 3:05
  • If this is Java then you need to remove JavaScript. They're not the same. Commented Mar 24, 2015 at 3:10

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.