【问题标题】:How to click image in a table in selenium如何单击硒表中的图像
【发布时间】:2021-01-08 15:48:21
【问题描述】:

在网页上,我有 3 个按钮,表格中有一个链接图像。我想单击图像。但我无法找到按钮为“发送”的图像

这是嵌入在表格中的图像的 HTML 代码:

<a class="ctl00_C_S_Z_ctrlActionToolbar_Menu1_1" href="javascript: ValidateSendMessage()>
<img src="ShmControls/ShmImages/SHM_Send_Trans.png" alt="Send Message" style="border-style:none;vertical-align:middle;>"Send" /a>

告诉我,如何在网页上找到此按钮?

我尝试使用以下所有选项来定位图像元素

IWebElement Send = driver.FindElement(By.XPath("a[@href= 'javascript: ValidateSendMessage()')]"));
IWebElement Send = driver.FindElement(By.XPath("//img[contains(src,'ShmControls/ShmImages/SHM_Send_Trans.png')]"));
IWebElement Send = driver.FindElement(By.XPath("//*@id='ctl00_C_S_Z_ctrlActionToolbar_Menu1']"));        
IWebElement Send = driver.FindElement(By.LinkText("ShmControls/ShmImages/SHM_Send_Trans.png"));  

【问题讨论】:

    标签: javascript selenium selenium-webdriver xpath css-selectors


    【解决方案1】:

    要点击带有发送文本的WebElement,您可以使用以下Locator Strategies

    • 使用CssSelector

      IWebElement Send = driver.FindElement(By.CssSelector("a[class*='ctrlActionToolbar_Menu'][href*='ValidateSendMessage']"));
      
    • 使用XPath

      IWebElement Send = driver.FindElement(By.XPath("//a[contains(@class, 'ctrlActionToolbar_Menu') and contains(@href, 'ValidateSendMessage')]"));
      

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多