rodrigozc

rodrigozc

Hello everyone,

I’m trying to automating navigation using Hound, but I’m having some troubles with select/option elements and how to interact with them.

For instance, I tried in different ways to select an option from the site “https://www.imovelweb.com.br/.

I tried the solution below but didn’t work.

https://github.com/HashNuke/hound/issues/72#issuecomment-178071219

I’m using the selenium driver with the chrome browser.

$ brew install selenium-server-standalone
$ selenium-server -port 4444
use Mix.Config

config :hound,
  driver: "selenium",
  browser: "chrome"

I tried to select in the following ways:

def search() do
    Hound.start_session()

    navigate_to(@url)

    find_element(:css, "#operationType option[value='1']")
    |> click

    #take_screenshot()

  rescue
    e ->
      IO.inspect(e)
      :notfound
  after
    Hound.end_session
  end

Error

%RuntimeError{
  message: "element not interactable: Element is not currently visible and may not be manipulated\n  (Session info: chrome=79.0.3945.88)\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'Rodrigos-MacBook-Pro.local', ip: '2804:14c:4a:9f9d:1591:2820:1fe7:d763', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.2', java.version: '1.8.0_131'\nDriver info: driver.version: unknown"
}
def search() do
    Hound.start_session()

    navigate_to(@url)

    find_element(:css, "#operationType")
    |> find_within_element(:css, "option[value='1']")
    |> click

    #take_screenshot()

  rescue
    e ->
      IO.inspect(e)
      :notfound
  after
    Hound.end_session
  end

Error

%RuntimeError{
  message: "element not interactable: Element is not currently visible and may not be manipulated\n  (Session info: chrome=79.0.3945.88)\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'Rodrigos-MacBook-Pro.local', ip: '2804:14c:4a:9f9d:1591:2820:1fe7:d763', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.2', java.version: '1.8.0_131'\nDriver info: driver.version: unknown"
}

I was wondering if I have to click on the select element before to show the options and then click on the chosen option, but when I tried to click on the select element I got another error.

def search() do
    Hound.start_session()

    navigate_to(@url)

    find_element(:css, "#operationType")
    |> click

    #take_screenshot()

  rescue
    e ->
      IO.inspect(e)
      :notfound
  after
    Hound.end_session
  end

Error

%RuntimeError{
  message: "element not interactable\n  (Session info: chrome=79.0.3945.88)\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'Rodrigos-MacBook-Pro.local', ip: '2804:14c:4a:9f9d:1591:2820:1fe7:d763', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.2', java.version: '1.8.0_131'\nDriver info: driver.version: unknown"
}

Thanks!

Showing Posts 1 to 9

wolfiton

wolfiton

I don’t see this in your code

use Hound.Helpers
hound_session()

This is what I am using to test by following this book https://shankardevy.com/phoenix-inside-out-mpf/ . But it uses phantomjs

Also if you use Linux install phantomjs like this Problem with acceptance test in hound not starting server on port 4001

Update found this in my tests, it might be similar with what you need:

find_element(:css, "#registration_residence_area option[value='Area 1']")
    |> click
rodrigozc

rodrigozc OP

I’m using hound to get some informations from a website, not for test purposes, sorry about my tag test, it’s not the case.

My module contains use Hound.Helpers, I think that hound_session() is used just in test cases to setup the session in the setup method.

I tried using PhantomJS too, in this case, I did not even make it select the option. When I inspected the HTML, the option values were blank. It’s weird, I know, so I changed the code to use the Selenium.

I’m starting and finishing the session in the method.

Below is the whole module.

defmodule PropertyCrawler.Imovelweb do
  use Hound.Helpers

  @url "https://www.imovelweb.com.br/"

  def search() do
    Hound.start_session()

    navigate_to(@url)

    find_element(:css, "#operationType option[value='1']")
    |> click

    #take_screenshot()

  rescue
    e ->
      IO.inspect(e)
      :notfound
  after
    Hound.end_session
  end

end
wolfiton

wolfiton

To use phantomjs you need to run this phantomjs --wd in a terminal window and at the same time in a new window your mix phx.server

That should work. If it doesn’t I really don’t know what is happening.

rodrigozc

rodrigozc OP

The idea is to use navigation with Hound to filter some data filling the form and after that to use Floki to parse data.

rodrigozc

rodrigozc OP

With PhantonJS I cannot find the element, executing the same find_element I got the error below.

%Hound.NoSuchElementError{
  parent: nil,
  selector: "#operationType option[value='1']",
  strategy: :css
}

Inspecting the #operationType element with PhantonJS I saw that all options had blank values.

<select name="" id="operationType">
  <option value="" selected="">Comprar</option>
  <option value="">Alugar</option>
  <option value="">Imóvel Novo</option>
  <option value="">Comercial</option>
  <option value="">Temporada</option>
</select>
wolfiton

wolfiton

This is strange have you tried to extract just an h1 tag to see if hound is working?

rodrigozc

rodrigozc OP

Yes, I can get h1 tag.

...
  find_element(:css, "h1")
  |> outer_html
...

Result:

iex(1)> PropertyCrawler.Imovelweb.search
"<h1>Você muda, <b>sua vida muda</b></h1>"
wolfiton

wolfiton

OK then how about writing your select like this:

<%= select f, :category_id, Enum.map(@categories, &{&1.name, &1.id}), prompt: "Choose a category" %>

If this doesn’t work either then try to create a minimal example only with a slect and test hound on that to see if that works.
If it does then you most certenly have a problem in your actual code or a bug.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews