willem

willem

Using phantomjs to interact and automate actions on a phoenix based web App

Hi everyone. I’ve come across html code containing “phx-click” and a google search has lead me to phoenix and this forum. I hope I’m at the right place and that someone here can help me.

First off, I don’t really know Javascript, so phoenix and elixir is completely foreign to me, I don’t even know how the two relate to each other.

I’m trying to automate changing a setting on a Web app for a device in my home using phantomjs. Note I can access the http webpage of the device, but do not have any control over the html or javascript code itself. Right now the obstacle I’m trying to pass is clicking on the following link:

<a href="#" phx-click="edit_settings" phx-target="1">edit</a>

Code in my phantomjs script is:

SetTimeout(function() {
    console.log("");
    console.log("### STEP 3: Click on edit link");
    page.evaluate(function() {
        var ev = document.createEvent("MouseEvents");
        ev.initEvent("click", true, true);
        document.querySelector("#settings > div > form > div > div.full > h3 > span > a").dispatchEvent(ev);
    });
}, 6000);

I’ve also tried replacing dispatchEvent(ev) with click().

As far as I can see the correct element is selected, but the page doesn’t switch to edit mode, i.e. doesn’t respond to the click. I’ve tried tracing what happens when the link is clicked in chrome Web tools, but then too the page doesn’t respond to the click. Any suggestions on how I can get the page to switch to edit mode.

From my searches online I’ve gathered that if a link is coded with the normal on-click attribute then the phoenix stuff don’t respond or work with that code and the opposite seem to be true as well. With the link having the phx-click attribute the normal click methods and events doesn’t seem to effect the link.

Ultimately I would like phantomjs to click above mentioned edit link, change a value in a drop down box and click the save button. I believe if I can get past the first edit link obstacle I should be able to manage the rest. I’m hoping that there is perhaps something like “element.phxclick(‘edit-settings’)” that can be used to trigger the click on that edit link. Any help or suggestions would be much appreciated. Even if the solution doesn’t involve using phantomjs. As long as it is a command line command I can enter to change the setting so that I can use that in another script again. Maybe one don’t even have to simulate the click and one can somehow just send the necessary data directly to the device using a http post, but I can’t figure out how the data is sent to the device either.

First Post!

kokolegorille

kokolegorille

Hello and welcome,

Elixir and Javascript are not related, they are different language.

Phoenix is a web framework and might use Javascript.

But all phx-click are related to Liveview, which is an attempt to avoid using JS. And You need to have a Phoenix server to use it.

And phantomjs… probably You use it as an http client, to control your device.

It’s possible to manage your device from an http client, but adding Phoenix to do this is not the easiest path :slight_smile:

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New

Other popular topics Top

AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement