-1

I need to click the image with an anchor tag using Selenium Webdriver Java.

<a title="Complete Step" class="tableIcon"           href="javascript:__doPostBack('__Page','COMPLETEJS_2309234_2_2_0')">
 <img title="Complete Step" style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px" src="/BTC/images/complete-job-step.png">
</a>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • From this information there is a very large number of possible answers. Can you narrow down your problem. Have a read through [ask] and [mcve]. – SiKing Mar 08 '19 at 19:23

3 Answers3

0

Simple xpath:

a.tableIcon img

if you have multiple links and "2309234_2_2_0" is the unique identifier, then user the below.

a[href$="COMPLETEJS_2309234_2_2_0')"] img
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • Hi @supputuri..that is where am facing the issue "a[href$="COMPLETEJS_2309234_2_2_0')"] img" here 2309234 is dynamic value it is changing everytime...is there anyother way for this – Ajith Naruto Mar 08 '19 at 16:12
  • Do you have multiple links with 'COMPLETEJS'? – supputuri Mar 08 '19 at 16:25
  • if you know the dynamic value in the 2309234 place then you can replace that with the new value? Can you get the dynamic value from the application (eg: if 2309234 is order number we can get that after the order). Please the snippet of the html code around that link, so that I might get more idea. – supputuri Mar 08 '19 at 17:21
0

Try the below Xpath.It should work.

"//a[@class='tableIcon']/img"
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

As the element is a dynamic element you have to induce WebDriverWait for the elementToBeClickable and you can use either of the following Locator Strategies:

  • Java Solution:

    • cssSelector:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.tableIcon[title='Complete Step']>img[title='Complete Step'][src*='complete-job-step']"))).click();
      
    • xpath:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='tableIcon' and @title='Complete Step']/img[@title='Complete Step' and contains(@src, 'complete-job-step')]"))).click();
      
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352