0

I'm trying to find the code to click on the following item and struggle with it for the last 5 days. Would you please help. The area i want to click is in BOLD below. Thanks,

<body class="tundra ltr">
<div id="dialogsContainer" class="dialogs" style="visibility: hidden; display: none;">
<div id="dialogsContainerStart"> </div>
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<div id="mdm_content" class="mdm_contentContainer">
<div id="mdm_Center" class="mdm_Center">
<div class="mdm_Body">
<div id="centerContentOuterDiv" class="policyProfile dijitContentPane" widgetid="centerContentOuterDiv">
<div id="navigationContainer" class="uwp_ContentMenuPane dijitContentPane" widgetid="navigationContainer">
<div class="uwp_ContentMenuPane">
<div class="uwp_ContentMenuPane_Title" onclick="togglePane('policyPane',false,'libraryHomeNav')">
<table class="uwp_layoutTableWide">
<tbody>
<tr>
<td class="uwp_layoutTableNarrow">
<td class="widgetImage mdm_policyIcon mdm_detailsIconWidth">
<td>
<td>
**<td class="uwp_layoutTableOpposite uwp_layoutTableNarrow">
<div id="addpolicy">
<img src="/admin/resources-4sch8xjaure9vmq5lgdafhi90/images/blank.gif" onclick="disableEventPropagation(event);return addLibraryItem('policy');">
</div>**
evilrod
  • 77
  • 1
  • 1
  • 10
  • These are what i tried: `code` String cssSelector="id[class='addpolicy']>img"; driver.findElement(By.cssSelector(cssSelector)).click(); – evilrod Sep 01 '15 at 22:37
  • `code`driver.findElement(By.id("x-auto-11-input")).findElement(By.xpath("//div[@id='addpolicy']")).click(); – evilrod Sep 01 '15 at 22:40
  • `code`driver.findElement(By.xpath("addpolicy")).click(); – evilrod Sep 01 '15 at 22:40
  • `code`driver.findElement(By.xpath("//td[@class='uwp_layoutTableOpposite uwp_layoutTableNarrow']/img'")).click(); – evilrod Sep 01 '15 at 22:40
  • `code`driver.findElement(By.cssSelector(".libraryMenuBlock > a[href='Add an IT policy']")).click(); – evilrod Sep 01 '15 at 22:40
  • `code`driver.findElement(By.xpath("//[id='libraryContentLandingDiv']/[3][@class='libraryMenuCol']/[3][@class='uwp_linkText']")).click(); – evilrod Sep 01 '15 at 22:41

3 Answers3

2

So the first thing that sticks out is this line of code,

<div id="dialogsContainer" class="dialogs" style="visibility: hidden; display: none;">

Notice the style, the visibility is set to hidden, and the display is none. Selenium will treat this the same, and you will not be able to click this item as it stands. You need to treat the flow the same as the user would, if the user can't see click the item, you will not be able to with Selenium.

You need to make this item visible to click an item inside this block. My guess is that there is an element on the page that you aren't showing us that would make this visible. Hope this helps.

broot02
  • 103
  • 1
  • 2
  • 11
  • This is not my code. it's a software and i have to create policy multiple time that's why i'm trying to write selenium script to do it so i don't have to repeat myself everyday. – evilrod Sep 02 '15 at 01:19
  • One thing is when i trying to catch the code with firebug or selenium it said externalid when i click on it manually. is there anyway at all? there are two place that i can click to be able to do the same thing. the addpolicy place or the "add an IT policy" location. – evilrod Sep 02 '15 at 01:20
  • So have you attempted to run this through Selenium IDE? – broot02 Sep 02 '15 at 03:43
  • Also perhaps you should take a look at this link. http://stackoverflow.com/questions/12040615/selenium-webdriver-clicking-on-hidden-element – broot02 Sep 02 '15 at 03:46
  • I tried to find the code in Selenium IDE and it said this: [link] http://imageshack.com/a/img911/1613/TxcFaz.png – evilrod Sep 02 '15 at 14:31
2

Can you click on it manually if you try? What is the error you get when you run your code?

If the button can be clicked manually, but you're not able to do this using Selenium, then try below JS:

   WebElement addPolicyButton = driver.findElement(By.xpath("//div[@‌​id='addpolicy']"); 

   JavascriptLibrary jsLib = new JavascriptLibrary(); 
   jsLib.callEmbeddedSelenium(driver,"triggerMouseEventAt", addPolicyButton,"click", "0,0");
ratsstack
  • 1,012
  • 4
  • 13
  • 32
  • i can click it manually there are two place to click... when i tried to ran the codes i had above it stop and said can't find such path... it said the path doesn't exist. – evilrod Sep 02 '15 at 01:22
  • i will give your a try and update you tomorrow since i do not have access to the software right now. – evilrod Sep 02 '15 at 01:23
  • my xpath could potentially be wrong (didn't spend much time looking at it). Use firebug to just get the minimum xpath and replace in my code. Just try and get the button click working first, then work on getting a robust xpath. – ratsstack Sep 02 '15 at 01:25
  • You welcome. Let me know how it goes. I am quite interested in finding solid ways of clicking stuff. Finding selenium is quite unforgiving when it comes to certain web elements. – ratsstack Sep 02 '15 at 03:34
  • when i tried your sample i got this error [link]http://imagizer.imageshack.us/v2/xq90/913/L9Qplg.png – evilrod Sep 02 '15 at 14:50
  • Change first line to: WebElement addPolicyButton = driver.findElement(By.id = "addpolicy"); – ratsstack Sep 02 '15 at 20:35
  • still not working bro same result..`code`Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"addpolicy"} Command duration or timeout: 10.08 seconds – evilrod Sep 02 '15 at 21:15
  • Do you have firepath installed? Can you right click on the button to be pushed and do an "inspect in firepath"? It should automatically provide the unique xpath for the button – ratsstack Sep 02 '15 at 22:01
  • here are the two places that i can click to go to the same place still not working .//*[@id='libraryOverviewTable']/tbody/tr[1]/td[1]/div[2]/div[3]/a and .//*[@id='addpolicy']/img – evilrod Sep 02 '15 at 22:06
  • I'm sorry man. I've got no idea. Unless I can get access to the website, I can't help any further. :-( – ratsstack Sep 02 '15 at 22:15
0

i was able to resolved it with this code below. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@name,'ExternalUI')]"))); driver.findElement(By.xpath("//a[contains(text(),'Add an IT policy')]")).click();

evilrod
  • 77
  • 1
  • 1
  • 10
  • Well, you didn't give us the full HTML! How were we to know the element was within a different frame?! if you want us to help you, you have to help yourself. – ratsstack Sep 03 '15 at 02:03
  • sorry bro i wish i know it's in different frame but i just google the externalUI and i found that... thanks – evilrod Sep 03 '15 at 22:40