Jump to content

Can you add new html to a page through xpath?


Recommended Posts

I will explain briefly what i'm doing.
At my work, we have a workflow that is very very hard on the eyes and very disorganised and also doesn't provide all the information needed to complete work on the initial screen. I'm creating a tool to monitor and perform some codes on each page.

The code currently will confirm the page its on, submit the code needed and then loop through a function checking until the page changes (based off the timestamp). I've started adding some extra data onto the work-page but i would like to add an extra column in a table.

So this is the HTML:
 

<tr>
<th localizer-text="GSR_Audio_Player_Info_Label">Audio Player Info</th>
<th localizer-text="GSR_Timestamp_Label">Timestamp</th>
<th localizer-text="GSR_Audio_Initiator_Label">Audio Initiator</th>
<th localizer-text="GSR_Start_Goal_Label">Start Goal</th>
<th localizer-text="GSR_End_Goal_Label">End Goal</th>
<th localizer-text="GSR_Dialog_Label">Dialog</th>
<th class="hidden audioPlayer" localizer-text="GSR_Audio_Player_Label">Audio Player</th>
<th localizer-text="GSR_StreamId_Label">StreamId</th>
</tr>

Currently i'm adding data into the 'StreamID' header and I also rename it.
Ideally i'd like to add a new header altogether so it would look liek this.
 

<tr>
<th localizer-text="GSR_Audio_Player_Info_Label">Audio Player Info</th>
<th localizer-text="GSR_Timestamp_Label">Timestamp</th>
<th localizer-text="GSR_Audio_Initiator_Label">Audio Initiator</th>
<th localizer-text="GSR_Start_Goal_Label">Start Goal</th>
<th localizer-text="GSR_End_Goal_Label">End Goal</th>
<th localizer-text="GSR_Dialog_Label">Dialog</th>
<th class="hidden audioPlayer" localizer-text="GSR_Audio_Player_Label">Audio Player</th>
<th localizer-text="GSR_StreamId_Label">StreamId</th>
<th localizer-text="GSR_StreamId_Label">NEW HEADER</th>
</tr>

Currently I have no idea how to do this, I was hoping based off previous code I could do something like this (shown below) but it doesn't seem to be as easy as that. I know if I could just write after the StreamID</th> I could then just write a new line of Html directly after it. Any advice? or snippets? please and thank you.
 

#include <FF.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "On_Exit")
HotKeySet("{F1}", "test")

_FFConnect(Default, default, 3000)

while 1
   sleep(50)
WEnd

func test()
   $test = _FFXpath("/html/body/form/section[1]/table/thead/tr")
   ;$test2 = _FFCmd("FFau3.xpath.insertCell='test'")
   ;$test2 = _FFCmd("FFau3.xpath.HTML='test'")
   ;$test2 = _FFCmd("FFau3.xpath.outerTEXT='test'")  
   ;$test2 = _FFCmd("FFau3.xpath.innerTEXT='test'")  
   $test2 = _FFCmd("FFau3.xpath.tr='test'") 
   MsgBox("", "", $test & " " & $test2)
EndFunc

func on_exit()
   Exit
EndFunc



 

Edited by Clerythecleric
Link to comment
Share on other sites

Hi, Thank you for replying.
I apologize for being a noob but I'm new to using Xpath and JavaScript ect within Autoit.
Reading the page, it has 2 parameters, Position and text. So with in Autoit how would I do that? I tried a few variations which i know are wrong (as they didn't work!)
 

_FFXPath("/html/body/form/section[1]/table/thead/tr/th[8]")
;_FFCmd("FFau3.xpath.insertAdjacentHTML='0 <test>'")
;_FFCmd("FFau3.xpath.insertAdjacentHTML='0' '<test>'")
_FFCmd("FFau3.xpath.insertAdjacentHTML=('0', '<div id='test'>two</div>')
$test2 = _FFCmd("FFau3.xpath.insertAdjacentText='afterBegin','Test 2'")



Again sorry, Though I'm learning alot off you. A week ago I had no clue whatsoever how to do any of this _FF stuff =). thank you =).

I did wonder if my FFPath is correct, that points towards the header node for the streamID, did i just want to go the the table?
 

/html/body/form/section[1]/table/thead/tr


I've tried it with text as well but i'm obviously doing this all wrong lol.
I also tried changing the Xpath to give the textcontent? Dunno if that would make a difference as to whats returned or not.
 

$test = _FFXpath("/html/body/form/section[1]/table/thead/tr/th[8]", "textContent")
;$test2 = _FFCmd("FFau3.xpath.insertAdjacentText=('afterend' 'test')")
;$test2 = _FFCmd("FFau3.xpath.insertAdjacentText='(afterend' 'test)'")
;$test2 = _FFCmd("FFau3.xpath.insertAdjacentText='afterend' 'test'")
$test2 = _FFCmd("FFau3.xpath.insertAdjacentText='afterend' 'test'")
MsgBox("", "", $test & " " & $test)

 

Edited by Clerythecleric
Link to comment
Share on other sites



Thanks for you help man, I honestly do appreciate it. I had to adapt the code slightly ( im guessing as you wrote it fast) and it no longer errors like my previous code but nothing happens? it doesn't work lol. There is that FFXPath_Error but that always comes up, even on my other code that works fine that shows.

Sorry to keep bugging you, but any ideas? I've been messing around with it alot, tried on some other elements but can't seem to create anything new.
 

_FFSendJavaScripts: Sending functions to FireFox .......... done
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("/html/body/form/section[1]/table/thead/tr/th[8]",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLTableCellElement] - {insertAdjacentText: "(afterEnd", insertAdjacentHTML: "<th localizer-text="GSR_New_Entry">NEW HEADER</th>", colSpan: 1, rowSpan: 1, headers: "", cellIndex: 7, abbr: "", ...}
__FFSend: FFau3.xpath.insertAdjacentHTML=('beforeend', '<th localizer-text="GSR_New_Entry">NEW HEADER</th>')
__FFRecv: <th localizer-text="GSR_New_Entry">NEW HEADER</th>
$test = _FFXPath("/html/body/form/section[1]/table/thead/tr/th[8]")
;MsgBox("", "", $test)
_FFCmd("FFau3.xpath.insertAdjacentHTML=('beforeend', '" & $sHTML & "')")

 

Edit:
So, If i now run just the path, it picks up this... So its registering the previous code as a property of this HtmlElement? (or any element that i run this code against). Instead of actually creating new HTML adjacent to this one?
 

__FFRecv: [object HTMLInputElement] - {insertAdjacentHTML: "<body>test</body>", insertAdjacentTEXT: "<body>test</body    >", stepUp: function() {...}, stepDown: function() {...}, checkValidity: function() {...}, reportValidity: function() {...}, setCustomValidity: function() {...}, ...}


_

Edited by Clerythecleric
Link to comment
Share on other sites

OK i'm done. Its working! :) I coudlnt get that code to work but found a simple way. Not as pretty but it works.


Thanks again buddy.

$sHTML = '<th localizer-text="GSR_New_Entry">NEW HEADER</th> <th localizer-text="GSR_New_Entry">NEW HEADER</th> <th localizer-text="GSR_New_Entry">NEW HEADER</th>'
$test = _FFXPath("/html/body/form/section[1]/table/thead/tr/th[8]")
_FFCmd("FFau3.xpath.outerHTML='" & $sHTML & "'")

 

Link to comment
Share on other sites

FWIW, this works for me --

#include <FF.au3>

If _FFConnect() Then
    _FFTabAdd( "https://www.autoitscript.com/")
    _FFXpath('//ul[@id="top-menu"]//li[@id="menu-item-1260"]')

    $sHTML = '<li id="menu-item-1261" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1261"><a href="https://www.autoitscript.com/site/autoit/autoit-books-resources/">Testing 123</a></li>'
    _FFCmd("FFau3.xpath.insertAdjacentHTML('afterend', '" & $sHTML & "')")
EndIf

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...