How to Retrieve XY Coordinates of a Word on a Webpage for Click Simulation?

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
122
Благодарностей
33
Баллы
28
Hello everyone!

I'm currently working on a project where I need to programmatically find the XY coordinates of a specific word displayed on a webpage. My goal is to eventually perform a simulated mouse click on this word. I've been attempting to accomplish this with JavaScript, but haven't had success yet.

Here's the scenario: The word "TEST" is visible on the page, and I need to retrieve its coordinates. I'm using ZennoPoster for automation, and my current approach involves executing JavaScript within the tool to get the element's position. However, I seem to be stuck.

Could anyone provide insights or code snippets on how to accurately find the coordinates of a word on a page? If it matters, I'm looking to do this in a browser environment controlled by ZennoPoster, which has its own methods for executing JavaScript and simulating mouse events.

Any help or direction would be greatly appreciated as I'm aiming to use these coordinates to then use ZennoPoster's mouse emulation block for the click action.

Thank you in advance for your assistance!
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
You don't need any javascript. Just search element(this case word) as you would normally with action designer. And then in step what to do with element you put radio button to GET and topInTab and leftInTab will be x, y coordinate points.
 
  • Спасибо
Реакции: Pierre Paul Jacques

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
122
Благодарностей
33
Баллы
28
@lokiys , your guidance was a game-changer and save my Sunday! :-)


Thanks to your suggestion, I was able to retrieve the coordinates without using into JavaScript, which simplified my process significantly.
117952


The objective behind my question was to embed Video after the second paragraph of my article—an action I couldn't directly perform within the HTML due to platform restrictions like medium.
Therefore, I crafted a workflow in ZennoPoster to accomplish this, which turned out to be quite an enlightening journey. I'm eager to hear your thoughts on this process and am open to suggestions. There may have been a simpler method that I overlooked, and I'm curious to learn about any alternative approaches?
(I know it is better by browserless and HTTP request for post article but i will implement this later)

Here's a quick rundown of the workflow I implemented on ZennoPoster:

  1. Scroll to Second Paragraph: First, I set up a C# code block to scroll down to the exact spot where the second paragraph begins. This ensures that we're working with the correct part of the webpage for the coordinate ( and not from the start of the page).
  2. Get Last Word: Using another C# code, I identify the last few words of this paragraph. This step is vital as it sets the stage for the following actions, even if it initially captures the start of the paragraph rather than the end.
  3. Mouse Emulation: Here's where your advice truly shined. I used the 'GET' function with the action designer, and the X, Y coordinates it returned allowed me to simulate a mouse click precisely where I needed it. When traditional Zenno Mouse Emulation didn't work, the C# mouse emulation ensured accuracy.
    Mouse Emulation:
    Emulator.MouseClick(instance.ActiveTab.Handle, MouseButton.Left, MouseButtonEvent.Click, 154, 266);

  4. Video Variable >> Clipboard: I utilized a C# block to copy my video URL (stored in the 'Video' variable) directly into the clipboard. This was crucial for speed and efficiency because texte emulation is too slow and sometime when do in custom way "fast" some field dont recognize it as text....
  5. Keyboard Emulation: Finally, with the ZennoPoster keyboard emulation block, I simulated the keyboard shortcuts to paste the video URL right after the second paragraph. This approach saved precious time compared to character-by-character input.

    Key:
    {CTRLDOWN}{DOWN}{CTRLUP}{CTRLDOWN}{DOWN}{CTRLUP}{LEFT}{ENTER}{CTRLDOWN}v{CTRLUP}{ENTER}
This entire sequence was about embedding a video player (like TikTok or YouTube) into my guest post without HTML access, and it worked flawlessly!

While this may not have been the most straightforward path, it was a valuable learning curve. I know more way navigate and manipulate web pages with ZennoPoster, all thanks to your tip on using the action designer for coordinate retrieval.

I'm grateful for your help, which not only solved my issue but also expanded my knowledge base. Your expertise is much appreciated!

117954
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
You are very welcome, bro. ;-)
As per your logic, unfortunately I can not help you much. You sent me whole project requirements. It would take at least an hour to go through all that very detailed with checking the exact page and thinking about the best logic to work.

Don't worry too much about good solution or bad solution, as I usually say there are only two types of projects,
* Onest that work and do what they have to do
* Ones that do not work.

So if you get done what you want, then this is a good project, PERIOD.

If in future you will increase threads and something will stop working or something will eat too much resources etc, etc. This is where you should think to update something. And by then you probably will have more experience and knowledge and will update as needed.
 
  • Спасибо
Реакции: Pierre Paul Jacques

Pierre Paul Jacques

Активный пользователь
Регистрация
08.10.2023
Сообщения
122
Благодарностей
33
Баллы
28
Don't worry too much about good solution or bad solution, as I usually say there are only two types of projects,
* Onest that work and do what they have to do
* Ones that do not work.


So if you get done what you want, then this is a good project, PERIOD.

If in future you will increase threads and something will stop working or something will eat too much resources etc, etc. This is where you should think to update something. And by then you probably will have more experience and knowledge and will update as needed.

You right,
is my trouble i still dont scale / multithread my project what i am doing because i am always customizing/pimping/optimizing my projet;-)
But the paradox for me with Zenno i discovered 2 thing : Development and Code!
Now i don't use my Wordpress anymore lol!
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)