簡體   English   中英

無法點擊圖片按鈕

[英]Unable to click image button

我正在嘗試單擊圖像按鈕,但是我正在獲取org.openqa.selenium.NoSuchElementException。 我什至通過迭代框架來檢查元素是否存在於任何iframe中。 它不在任何框架中。 我想念什么嗎? 有人可以幫我這個忙。

下面是我正在嘗試的代碼:

WebDriverWait wait2 = new WebDriverWait(driver,30);  
WebElement image = wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']")));  
actions.click(image).build().perform();

我得到的例外:

Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 45 seconds waiting for visibility of element located by By.xpath: //tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'W1856237', ip: '192.168.43.137', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
    at com.ExpTestcases.TestOne.main(TestOne.java:105)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//tr//table[@title='User Prompt Input']//div[@id='IconImg_vertBar_leftPaneW_icon_3']"}
  (Session info: chrome=70.0.3538.77)

這是圖像按鈕的html代碼:

<table role="button" aria-label="User Prompt Input" aria-pressed="false" title="User Prompt Input" style="display: block; cursor: pointer;" false"="" margin:0px"="" id="vertBar_leftPaneW_icon_3" class="" cellspacing="0" cellpadding="0" border="0" aria-labelledby="ariaLabelledBy_vertBar_leftPaneW_icon_3" tabindex="0">
        <tbody>
            <tr valign="middle">
                <td id="iconleft_vertBar_leftPaneW_icon_3" class="">
                    <div style="width:2px;height:35px"></div>
                </td>
                <td id="iconmid_vertBar_leftPaneW_icon_3" align="center" style="height:35px;" class="">
                    <div style="overflow:hidden;height:31px;" valign="middle">
                    <div id="IconImg_vertBar_leftPaneW_icon_3" class="imo" style="width:31px;height:31px;background-image:url('images/main/vertbar_icons.png');background-position:-1px -127px;margin-top:2px;cursor:pointer"></div>
                    </div>
                </td>
                <td id="iconright_vertBar_leftPaneW_icon_3" class="">
                    <div style="width:2px;height:35px"></div>
                </td>
            </tr>
        </tbody>
    </table>

Xpath試用:

  • // table [@ aria-label =“用戶提示輸入”]

  • // tr // table [@ title ='用戶提示輸入'] // div [@ id ='IconImg_vertBar_leftPaneW_icon_3']

  • // table [@ aria-label =“用戶提示輸入”] / @ title

  • // tr // table [@ aria-label =“用戶提示輸入”] / @ title

當你試圖調用click()的元素使,而不是使用visibilityOfElementLocated()方法,你需要使用elementToBeClickable()方法,可以使用以下兩種解決方案:

  • cssSelector

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("table[id^='vertBar_leftPaneW_icon_'][aria-label='User Prompt Input'] div.imo[id^='IconImg_vertBar_leftPaneW_icon_'][style*='vertbar_icons']"))).click(); 
  • xpath

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[starts-with(@id,'vertBar_leftPaneW_icon_') and @aria-label='User Prompt Input']//div[@class='imo' and starts-with(@id,'IconImg_vertBar_leftPaneW_icon_')][contains(@style,'vertbar_icons')]"))).click(); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM