0

I know the ID of the image button but still can't click using :

driver.findElement(By.id("its Id")).click()

Can't provide website link as its not a public website but pasting the HTML for the specified webelement.

<div ondragstart="var e=window.event;e.cancelBubble=true;e.returnValue=false;return false;" draggable="false" id="WD0191" ct="B" lsdata="{4:'Add\x20All',10:true,12:'\x2fsap\x2fpublic\x2fbc\x2fur\x2fnw5\x2fthemes\x2f\x7ecache\x2d20171002133000\x2fBase\x2fbaseLib\x2fsap_belize\x2fsvg\x2flibs\x2fSAPGUI\x2dicons.svg\x23s_pagedo'}" lsevents="{Press:[{ResponseData:'delta',ClientAction:'submit'},{}]}" role="button" aria-labelledby="WD0191-arialabel" title="Add All " tabindex="0" ti="0" class="lsButton lsTbarBtnStd urInlineMetricTop urNoUserSelect urBtnRadius  lsButton--onlyImage  urBtnImgBgColor lsButton--design-standard urBtnStd">
  <span id="WD0191-cnt" class="urNoUserSelect lsButton--content lsControl--centeraligned " style="pointer-events:none;">
    <svg data-sap-ls-svg-inline="true" data-sap-ls-svg-inlinehtmlexchange="true" id="WD0191-img" alt="Add All " tabindex="-1" ti="-1" focusable="false" preserveAspectRatio="none" viewBox="0 0 100 100" class="urSvgAppIconMetric urSvgAppIconColorBase urSvgAppIconVAlign urImgBtn lsButton__image" style="nop:nop;margin-top: 0px;;nop:nop;">
      <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#_SAPGUI-icons_1_s_pagedo"></use>
    </svg>
    <span class="lsButton--onlyImage-pusher" style="display:inline-block;width:0;">&nbsp;</span>
  </span>
  <span id="WD0191-arialabel" style="display:none;visibility:hidden;">Add All</span>
</div> 

Can any one suggest how I can click on it by any other way?

Update: When i try to click on it using click() it just kind of moves the mouse to that element. So yes i am sure it identifies the item correctly. But somehow clicking it using webdriver doesn't gives the same result as it would if clicked manually.

I think because the javascript written for this element is not getting triggered when i click it using webdriver thats why i don't get desired result.

I have tried using:

new Actions(driver).moveToElement(input).click().perform();

But no results.

Update: what the button is used for and in bigger picture inside which div tag it is. This button is inside a table which is divided in two parts in first part of the table you fetch results based on some search criteria and if they are relevant you copy them to the second part of the table using this image button.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Archana
  • 57
  • 7
  • had you check if this html code is into a frame? – j.barrio Feb 22 '18 at 15:17
  • I see four different IDs in the code provided. Which ID are you using to click? – MivaScott Feb 22 '18 at 16:41
  • @j.barrio Yes its in a frame have already switched to that frame it has other elements as well for them click() is working. – Archana Feb 22 '18 at 17:07
  • @MivaScott I am using "WD0191" this ID which is for the div tag – Archana Feb 22 '18 at 17:09
  • Possible duplicate of [Selenium WebDriver \[Java\]: How to Click on elements within an SVG using XPath](https://stackoverflow.com/questions/41829000/selenium-webdriver-java-how-to-click-on-elements-within-an-svg-using-xpath) – undetected Selenium Feb 23 '18 at 07:46
  • @DebanjanB how is it similar to your question? because here the element which needs to receive the click is the one with div tag and not the one with svg tag. and even if i try to click on svg tag element i can use its id directly as its unique so i don't need to make an xpath for it. – Archana Feb 25 '18 at 18:55
  • @DebanjanB and even if i try to click on svg element using its id it gives me this error : unknown error: Element ... is not clickable at point (75, 402). Other element would receive the click:
    – Archana Feb 25 '18 at 18:58

3 Answers3

2

Try with JavascriptExecutor:

    WebElement ele1 = driver.findElement(By.id("ITS ID"));
    JavascriptExecutor clickbtn = (JavascriptExecutor)driver;
    clickbtn.executeScript("arguments[0].click();", ele1);
Sneha Shinde
  • 366
  • 1
  • 7
0

Can u try using element.submit () If that doesn't work , try using JavaScript executor...

  • I tried doing element.submit() but its gives an error stating "no such element: Element was not in a form, so could not submit." . And to set context this button is inside a table which is divided in two parts in first part of the table you fetch results based on search and if they are relevant you copy them to the second part of the table using this image button. – Archana Feb 23 '18 at 06:17
0

I got the answer, actually i was clicking on the image button before the data was fetched in the table one so the button was clicked before there was any data to pass on to the second table and it was giving me an impression that though the button is getting clicked but still the data is not going from table one to table two upon clicking the button. Now have added explicit wait for 5000 and its working as expected.

Though thanks everyone for your inputs.

@Sneha Shinde thanks.. got to know about this wait issue while trying your solution to use javascript executor.

Though in my case simple element.click() is also working after putting wait.

Archana
  • 57
  • 7