无法使用具有<em unselectable =“on”> </em>属性的Webdriver单击iframe中的按钮

时间:2013-09-24 15:29:37

标签: javascript iframe xpath webdriver selenium-webdriver

我需要点击我们的应用程序中的“以全屏模式显示”按钮。

以下是使用firebug找到的html内容

    <iframe class="gwt-Frame" src="/designer/editor/?uuid=1cca23be-5a43-4506-962e-b9124d463469&profile=jbpm" domain="bg-sipstage1" style="width: 100%; height: 580px;" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html class=" ext-strict x-viewport x-viewport" xmlns="http://www.w3.org/1999/xhtml" xmlns:b3mn="http://b3mn.org/2007/b3mn" xmlns:ext="http://b3mn.org/2007/ext" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:atom="http://b3mn.org/2007/atom+xhtml">
    <head profile="http://purl.org/NET/erdf/profile">
    <body id="jbpmdesigner" class=" ext-gecko x-border-layout-ct x-body-masked" style="overflow: hidden; position: relative;">
    <div id="ext-comp-1008" class=" x-panel x-panel-editor-north x-border-panel x-panel-noborder" style="left: 0px; top: 0px; width: 1625px;">
    <div id="ext-gen18" class="x-panel-bwrap">
    <div id="ext-gen19" class="x-panel-body x-panel-body-noheader x-panel-body-noborder" style="height: 24px; width: 1625px;">
    <div id="ext-comp-1014" class="x-panel x-panel-noborder">
    <div id="ext-comp-1023" class="x-toolbar x-small-editor" style="height: 19px;">
    <table cellspacing="0">
    <tr>
    <td id="ext-gen299">
    <td id="ext-gen307">
    <td id="ext-gen315">
    <td id="ext-gen323">
    <td>
    <td id="ext-gen332">
    <td id="ext-gen340">
    <td id="ext-gen348">
    <td id="ext-gen356">
    <td id="ext-gen1095">
    <td id="ext-gen365">
    <td id="ext-gen373">
    <td id="ext-gen1092">
    <td id="ext-gen382">
    <td id="ext-gen390">
    <td id="ext-gen484">
    <table id="ext-comp-1046" class="x-btn-menu-wrap x-btn x-btn-icon " cellspacing="0" style="width: 36px;"></td>
    <td id="ext-gen493"><table id="ext-comp-1048" class="x-btn-menu-wrap x-btn x-btn-icon " cellspacing="0" style="width: 36px;"></td>
    <td id="ext-gen502"><table id="ext-comp-1050" class="x-btn-menu-wrap x-btn x-btn-icon " cellspacing="0" style="width: 36px;"></td>
    <td id="ext-gen510"><table id="ext-comp-1053" class="x-btn-wrap x-btn x-btn-icon " cellspacing="0" cellpadding="0" border="0" style="width: auto;">
    <tbody>
    <tr>
    <td class="x-btn-left" id="ext-gen736">
    <td class="x-btn-center" id="ext-gen755">
    <em unselectable="on"><button id="ext-gen512" class="x-btn-text" type="button" style="background-image: url("/designer/images/fullscreen.png");" title="Show in full screen mode"> </button>
    </em>
    </td>
    <td id="ext-gen735" class="x-btn-right">
    </tr>
    </tbody>
    </table>
    </td>

我可以使用以下xpath

识别或找到“以全屏模式显示”

1)public By FullScreen = By.xpath(“// [@ id ='ext-comp-1053'] / / * / [2] / / *“);

2)public By FullScreen = By.xpath(“// * [contains(@title,'以全屏模式显示')]”);

但无法点击按钮。我使用了以下两种方法 我尝试使用.click()方法

Actions.WaitForElement(......FullScreen);
Actions.MoveToElement(.......FullScreen);
driver.findElement(........FullScreen).click();

即使我尝试使用javascript点击

WebElement fullscreen=driver.findElement(WorkflowLocators.FullScreen);
JavascriptExecutor executor2 = (JavascriptExecutor)driver; 
executor2.executeScript("arguments[0].click();", fullscreen); 

在两种情况下都没有点击按钮。

1 个答案:

答案 0 :(得分:0)

在html标记中嵌套引号(如style="background-image: url("/designer/images/fullscreen.png");")可能会使xpath难以解析它。考虑用单引号替换内部引用。

至于您的具体问题,您应该能够使用更简单的方法来定位要单击的元素,只使用button元素的id。 Web元素上的ID属性在该页面中应该是唯一的。尝试使用By.id("ext-gen512")