2015-07-05 21 views
0

本質上,我有一個Safari瀏覽器中巨大表格的鏈接。我想始終單擊第2行第1列。該單元格內的鏈接名稱發生更改。點擊表格內的Safari中的鏈接

下面是HTML http://pastebin.com/UuwFfcyG

我把視覺標記在我想點擊的代碼。但在這個例子中,你可以搜索「1222」,它會拉起來。

基本上一旦鏈接被點擊它打開,我可以再次破解四周,使用的系統事件標籤,並選擇東西,然後重新加載該頁面,並做到一個窗口。

獎金,如果你能告訴我如何檢查在下一列的文本。第2列2.如果它顯示「打開」,則單擊左側單元格中的鏈接。

充分披露我寫了一個AppleScript的程序,這樣做,但它確實是使用屏幕座標管轄蟒蛇點擊,所以如果分辨率改變或添加其他監視器它打破了計劃。這是如此hacky,但它絕對有效。我只是尋找更原生的東西。

任何幫助,將不勝感激!由於 布蘭登

回答

0

,讓您自動想看看是否有第2行中的鏈接,該表的第1列,並點擊它?

<script LANGUAGE="Javascript"> 
function clickLinksInTable(i) { 
    // check if a link even exists in this row 
    if (!document.getElementsByTagName("tr")[i+1].getElementsByTagName("td")[0].getElementsByTagName("a")[0] || !document.getElementsByTagName("tr")[i+1].getElementsByTagName("td")[1]) { 
     // fail silently. 
    } else { 
     // check if the next column to the right contains the word "open" . 
     if (document.getElementsByTagName("tr")[i+1].getElementsByTagName("td")[1].innerHTML.toLowerCase().indexOf("open") != -1) { 
      // get the row (tr) that the user wants (the first row never contains a link, so add one to i to avoid this being a problem) 
      // then get the first column (td) in that row, and then get the first (probably only) link in that column. 
      link = document.getElementsByTagName("tr")[i+1].getElementsByTagName("td")[0].getElementsByTagName("a")[0]; 
      // then... click on it! While we're mainly focussed on Safari, it's good to support other browsers as well, 
      // just in case we want to use this code again elsewhere. 
      // Firefox 
      if (document.createEvent) { 
       var event = document.createEvent("MouseEvents"); 
       event.initEvent("click", true, true); 
       link.dispatchEvent(event); 
      } 
      // IE 
      else if (link.click) { 
       link.click(); 
      } 
     } 
    } 
} 
// call the function we made earlier. The value in brackets is the row number of the link you want to click. 
// this will click the link in row two, column one. 
clickLinksInTable(0); 
// this would click the link in row five, column one. 
//clickLinksInTable(3); 
</script> 

在你的表格後添加這個。

+0

那裏總是有一個鏈接。但我不需要點擊它,除非它說打開 – Brandon

+0

這是否做你想要的東西? 或者你的意思是第2行第3列?說這裏過期了嗎?目前,我有它檢查第2行,第2列。 – tomysshadow

+0

原諒我我不知道如何可以包裝在Applescript中。是否可以只用一行點擊該鏈接?如果我能弄清楚如何點擊第一個鏈接,我可以通過Applescript添加邏輯。 我並不是真的很擔心閱讀其他行,但如果只有一行我可以使用它可能將其複製到剪貼板,或者甚至更好地將該字符串存儲在變量中我可能會弄清楚如何將它傳回以applescript。我也非常感謝你的幫助。 http://i.imgur.com/iMPQdjK.png – Brandon