etaoin

RAJKUMAR 2024-04-26T21:40:49.813549Z

I've query (e/query driver {:tag :a :fn/link "" :index 1})

RAJKUMAR 2024-04-26T21:41:09.597809Z

how can I select the parent element of the above query?

lread 2024-04-26T23:41:47.784399Z

Good question @raj.psgit! Here's me playing in my REPL:

(require '[etaoin.api :as e])

(def driver (e/firefox))

;; I'll amble over to a page we can both play with...
(e/go driver "")

;; And do a similar query to what you specified
(def elem (e/query driver {:tag :a :fn/link "" :index 1}))

;; Let's inspect a bit (looks good)
(e/get-element-tag-el driver elem)
;; => "a"
(e/get-element-inner-html-el driver elem)
;; => "ClojureScript Cheatsheet"

;; And this is counter-intuitive, I think, but it seems you can use the child fn to ask for the parent via XPath
(def parent-elem (e/child driver elem ".."))

;; This seems to work fine!
(e/get-element-tag-el driver parent-elem)
;; => "p"
(e/get-element-inner-html-el driver parent-elem)
;; => "<a href=\"\">ClojureScript Cheatsheet</a>"

(e/quit driver)
So, in my dabbling here, I've found I can use the child fn to get to its parent element. Lemme know if this helps, works for you, and answers your question.

RAJKUMAR 2024-04-26T23:51:07.365669Z

sounds good @lee the answer is (e/child driver elem "..") which is from your snippet 🙂

lread 2024-04-27T00:05:46.794769Z

yes you read it correctly

RAJKUMAR 2024-04-26T23:41:51.619219Z

Hi I need help with etaoin for the following scenario

lread 2024-04-27T14:54:11.788779Z

@raj.psgit you were close. Here's what I did below: 1. switched child to children to get all td tags. 2. turfed the parent-tr count is println, you were printing the length of the webdriver element id string 3. printed from the returned td-els 4. switched to doseq from for because for is lazy and won't be realized outside of a REPL Continuing from the REPL session I showed above:

(let [parent-tr (e/query driver {:css "tbody > tr:last-child"})
      td-els   (e/children driver parent-tr {:tag :td})]
  (println "tds count is " (count td-els))
  (doseq [td td-els]
    (println "td text" (e/get-element-text-el driver td))))
Here's what this outputs for me:
tds count is  5
td text Totals:
td text 
td text 84.65 %
td text 
td text 97.08 %

RAJKUMAR 2024-04-28T04:07:17.971249Z

Awesome. Thanks @lee it works

👍 1
RAJKUMAR 2024-04-26T23:42:23.167729Z

let say I have html attached here

RAJKUMAR 2024-04-26T23:43:10.474659Z

RAJKUMAR 2024-04-26T23:44:47.043169Z

I need to get the last <tr> element in the html inside the iframe, <#document> and again <html> and <body>

RAJKUMAR 2024-04-26T23:46:01.211909Z

here is the screenshot of the inspect of the webpage

RAJKUMAR 2024-04-26T23:46:25.160239Z

I wrote the code like this

RAJKUMAR 2024-04-26T23:47:40.986909Z

RAJKUMAR 2024-04-26T23:48:51.140669Z

I'm getting false response for (println (e/exists? driver :myframe))

RAJKUMAR 2024-04-26T23:48:53.777179Z

any idea?

lread 2024-04-26T23:51:35.840479Z

Have you read our user guide on this topic yet? https://cljdoc.org/d/etaoin/etaoin/1.0.40/doc/user-guide#_working_with_frames_and_iframes

RAJKUMAR 2024-04-26T23:52:28.892709Z

yeap if you see my code above I've tried (e/switch-frame driver :myframe)

lread 2024-04-26T23:52:41.683269Z

Coolio

RAJKUMAR 2024-04-26T23:52:49.923529Z

but it is not working

RAJKUMAR 2024-04-26T23:53:05.119759Z

I think it is because iframe inturn contains html document

RAJKUMAR 2024-04-26T23:53:41.223369Z

but also it is I'm not sure why (println (e/exists? driver :myframe)) returns false

lread 2024-04-26T23:55:42.875949Z

I think maybe because you've switched inside the frame you can no longer see the frame element. Lemme try your HTML from here... just a sec.

lread 2024-04-27T00:05:13.747399Z

I'm foggy on iframes in general... hold on another sec...

lread 2024-04-27T00:10:11.141479Z

Oh... I think you were trying to convey in your HTML example that your iframe index.html is the content between the #document tags? Is that... your intent?

RAJKUMAR 2024-04-27T00:11:51.292919Z

what I'm trying to do is to get all the <tr> tags elements

lread 2024-04-27T00:12:29.881439Z

I'm trying your sample html and it seems incorrect. My question is related to that.

RAJKUMAR 2024-04-27T00:13:06.344519Z

what you think is incorrect

RAJKUMAR 2024-04-27T00:13:35.820679Z

if that is helpful

lread 2024-04-27T00:14:32.047609Z

Ah you are working from the inspector only and not files?

lread 2024-04-27T00:14:54.367459Z

That's why I can't simply try your HTML sample.

RAJKUMAR 2024-04-27T00:14:57.234159Z

I took the screenshot if the html above is confusing

lread 2024-04-27T00:16:36.609369Z

So @raj.psgit, you gave me some HTML. I assumed I could use this to replicate your problem, but you just pasted it from the inspector. Now that I understand this, I can can rework your example HTML to something I can use and help you more.

RAJKUMAR 2024-04-27T00:21:47.512549Z

got it

RAJKUMAR 2024-04-27T00:22:08.286799Z

lread 2024-04-27T00:22:38.662299Z

Oh no please. I'm good with what I have no need to paste more HTML!

RAJKUMAR 2024-04-27T00:22:39.941929Z

when I did the file save as

RAJKUMAR 2024-04-27T00:23:14.937979Z

okay 🙂

lread 2024-04-27T00:25:28.726799Z

simple_smile

lread 2024-04-27T00:29:25.449209Z

Ok, I've saved your html and iframe HTML to separate files in my fiddle directory. fiddle/slack2024-04-26.html

<html xmlns="" xml:lang="en" lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html">
      <!-- CSS Tabs is licensed under Creative Commons Attribution 3.0 -  -->
   </head>
   <body onload="init('tab1');">
      <h1><a id="hudson_link" href="/job/Services/job/project-name/job/master/6121/">Back to #6121</a></h1>
      <h2><a id="zip_link" href="*zip*/Cloverage_20report.zip">Zip</a></h2>
      <ul id="tabnav">
         <li id="tab1" class="selected" onclick="updateBody('tab1')" value="index.html">Cloverage report</li>
         <script type="text/javascript">document.getElementById("hudson_link").innerHTML="Back to #6121";</script><script type="text/javascript">document.getElementById("hudson_link").href="/job/Services/job/project-name/job/master/6121/";</script><script type="text/javascript">document.getElementById("zip_link").href="*zip*/Cloverage_20report.zip";</script>
      </ul>
      <div>
         <iframe id="myframe" height="100%" width="100%" frameborder="0" src="slack2024-04-26-iframe.html" style="height: 26px;">
         </iframe>
      </div>
      </body>
</html>
And the iframe source fiddle/slack2024-04-26-iframe.html
<html>
               <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                  <link rel="stylesheet" href="./coverage.css">
                  <title>Coverage Summary</title>
               </head>
               <body>
                  <table>
                     <thead>
                        <tr>
                           <td class="ns-name"> Namespace </td>
                           <td class="with-bar"> Forms </td>
                           <td class="with-number">Forms %</td>
                           <td class="with-bar"> Lines </td>
                           <td class="with-number">Lines %</td>
                           <td class="with-number">Total</td>
                           <td class="with-number">Blank</td>
                           <td class="with-number">Instrumented</td>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                        <tr>
                           <td>Totals:</td>
                           <td class="with-bar"></td>
                           <td class="with-number">84.65 %</td>
                           <td class="with-bar"></td>
                           <td class="with-number">97.08 %</td>
                        </tr>
                     </tbody>
                  </table>
               </body>
               <html>

lread 2024-04-27T00:32:50.628709Z

So working with this in my REPL let's fire up a firefox session and bring up the test page:

(require '[etaoin.api :as e]
         '[ :as io])

(def driver (e/firefox))

(e/go driver (-> "fiddle/slack2024-04-26.html" io/file .toURI str))
Now, notice that we can find the :myframe element before we switch to it:
(e/exists? driver :myframe)
;; => true
But after we switch inside the iframe we can no longer see the iframe element (because we are inside it):
(e/switch-frame driver :myframe)

(e/exists? driver :myframe)
;; => false
Now that we are inside the iframe, I'll search for the last tr in the tbody like so:
(def elem (e/query driver {:css "tbody > tr:last-child"}))
And let's see if we go what we expected:
(e/get-element-tag-el driver elem)
;; => "tr"

(e/get-element-text-el driver elem)
;; => "Totals: 84.65 % 97.08 %"
I think that looks good.

lread 2024-04-27T00:33:36.100639Z

Does that help?

RAJKUMAR 2024-04-27T00:36:54.766699Z

yes it helped 🙂

RAJKUMAR 2024-04-27T00:37:00.490629Z

thank you so much

lread 2024-04-27T00:58:17.810309Z

You are welcome, @raj.psgit; feel free to drop by if you get stuck again with Etaoin.

RAJKUMAR 2024-04-27T00:59:06.107999Z

sure Iread

RAJKUMAR 2024-04-27T05:49:10.770659Z

Hey @lee one more question

RAJKUMAR 2024-04-27T05:49:29.447889Z

I want to return child <td> as vector

RAJKUMAR 2024-04-27T05:49:42.561869Z

(let [parent-tr (e/query driver {:css "tbody > tr:last-child"})
      td-els   (e/child driver parent-tr {:tag :td})]
  (println "parent-tr count is " (count parent-tr))
  (println "row-els count is " (count td-els))
  (for [row parent-tr]
    (println (e/get-element-text-el driver row)))
  #_(clojure.pprint/pprint (map  #(e/get-element-text driver %) td-els)))

RAJKUMAR 2024-04-27T05:50:11.265229Z

the final for is not printing anything any idea?