splinter icon indicating copy to clipboard operation
splinter copied to clipboard

javascript:void(0) - issue to click on menu

Open yannlm1 opened this issue 8 years ago • 14 comments

Splinter version 0.7.7 Python version 2.7.5

Hello All,

I'm struggling for clicking on this menu as below:

<a class="buttons" id="STR_TOPNAV_REMOTE_CONTROL" href="javascript:void(0)" lnavobj="RMCNTRL_LEFTNAV">Remote Control</a>

I also tried by class, Xpath, by ID with no luck, would you have any suggestion?

Thanks

yannlm1 avatar May 04 '18 08:05 yannlm1

@yannlm1 what driver are you using and how are you trying? I believe that `browser.find_by_id("STR_TOPNAV_REMOTE_CONTROL").click()" should works.

andrewsmedina avatar May 04 '18 18:05 andrewsmedina

Hello,

I'm using geckodriver 0.20.0, with firefox version 59.0.2, I also tried by id, but didn't find the element as below:

Traceback (most recent call last):
  File "./kvm.py", line 24, in <module>
    browser.find_by_id("STR_TOPNAV_REMOTE_CONTROL").first.click()
  File "/usr/lib/python2.7/site-packages/splinter/element_list.py", line 53, in first
    return self[0]
  File "/usr/lib/python2.7/site-packages/splinter/element_list.py", line 44, in __getitem__
    self.find_by, self.query))
splinter.exceptions.ElementDoesNotExist: no elements could be found with id "STR_TOPNAV_REMOTE_CONTROL"

Here my code

#!/usr/bin/python
from splinter import Browser
import time
import getpass

pswd = getpass.getpass('Password:')

browser = Browser()
# Visit URL
url = "http://IP/page/login.html"

browser.visit(url)
browser.fill('T1', 'root')
browser.fill('T2', pswd)
browser.find_by_id("LOGIN_VALUE_1").first.click()
time.sleep(3)
browser.find_by_id("STR_TOPNAV_REMOTE_CONTROL").first.click()

yannlm1 avatar May 07 '18 12:05 yannlm1

I believe that the problem should be that when you try to get the STR_TOPNAV_REMOTE_CONTROL this element is not present yet. Maybe wait 3 seconds is not enougth.

A better approach is to use is_element_present instead the time.sleep:

browser.is_element_present_by_id("STR_TOPNAV_REMOTE_CONTROL", wait_time=10)

andrewsmedina avatar May 07 '18 17:05 andrewsmedina

In this example the use of first is not necessary. splinter aways will try to do an action in the first element if no one is specified. So you can replace browser.find_by_id("LOGIN_VALUE_1").first.click() by browser.find_by_id("LOGIN_VALUE_1").click()

andrewsmedina avatar May 07 '18 17:05 andrewsmedina

Thanks, So I tried with is_element_present browser.is_element_present_by_id("STR_TOPNAV_REMOTE_CONTROL", wait_time=10) I kept after browser.find_by_id("STR_TOPNAV_REMOTE_CONTROL").first.click()

Result: splinter.exceptions.ElementDoesNotExist: no elements could be found with id "STR_TOPNAV_REMOTE_CONTROL"

yannlm1 avatar May 08 '18 06:05 yannlm1

@yannlm1 are you sure that the STR_TOPNAV_REMOTE_CONTROL element is present after login?

andrewsmedina avatar May 08 '18 14:05 andrewsmedina

As below, it's looks like, I need to put the focus (mouse) on the menu tab, and then it's highlighted. How can I do this with splinter? remote control

I tried to leave just browser.is_element_present_by_id("STR_TOPNAV_REMOTE_CONTROL", wait_time=10), and remove browser.find_by_id, I don't any output saying element is present.

Thanks.

yannlm1 avatar May 08 '18 15:05 yannlm1

The is_element_present_by_id returns True if the element is present.

This html with STR_TOPNAV_REMOTE_CONTROL element is in the same html, can you check if it was in an iframe?

andrewsmedina avatar May 08 '18 16:05 andrewsmedina

Ok, yes in the same html page, as below the frame name.

<frameset rows="207, *" border="0" bordercolor="rgb(192, 192, 192)" frameborder="no" framespacing="0">
<frame src="page/header.html" id="HEADER" name="header" scrolling="auto" noresize="noresize">

Thanks,

yannlm1 avatar May 09 '18 15:05 yannlm1

You should use get_iframe to manipulated elements inside a frame: http://splinter.readthedocs.io/en/latest/iframes-and-alerts.html#using-iframes

andrewsmedina avatar May 09 '18 19:05 andrewsmedina

Thanks, it worked! How can I handle jnlp file? Basically the next step is to click on a button in order to launch a java program for displaying the server's kvm.

yannlm1 avatar May 17 '18 12:05 yannlm1

Hello Andrew,

Could you please have a look to my question?

Thanks.

yannlm1 avatar May 28 '18 15:05 yannlm1

I don't know how to do it :(

andrewsmedina avatar May 28 '18 16:05 andrewsmedina

In fact when I'm doing it with iframe, and I click on Open With (jviewer.jnlp), it's failing. As below the logs from geckodriver: INFO: >>> JWS: parsed jnlp after 99ms; jnlp=/tmp/mozilla_ylemouel0/jviewer-1.jnlp INFO: extracted 2 native libs from Linux_x86_64.jar INFO: >>> JWS: checked and (if necessary) deployed jars after 397ms: to directory /local/java.users/ylemouel/.java/deployment/cache/jws/jviewer-1__0.0.0; jnlp=/tmp/mozilla_ylemouel0/jviewer-1.jnlp INFO: >>> JWS: launching with the following command line: INFO: >>> JWS: /local/java.users/ylemouel/.java/deployment/cache/jws/jviewer-1__0.0.0/jviewer-1.jnlp_1_8.jws INFO: >>> JWS: -cp INFO: >>> JWS: /local/java.users/ylemouel/.java/deployment/cache/jws/jviewer-1__0.0.0/* INFO: >>> JWS: -Djava.library.path=/local/java.users/ylemouel/.java/deployment/cache/jws/jviewer-1__0.0.0 INFO: >>> JWS: INFO: >>> JWS: 10.8.160.113 INFO: >>> JWS: 7578 INFO: >>> JWS: K8bMfc2fMzupGFqT INFO: >>> JWS: 0 INFO: >>> JWS: 0 INFO: >>> JWS: 0 INFO: >>> JWS: 5120 INFO: >>> JWS: 5123 INFO: >>> JWS: 255 INFO: >>> JWS: ":Ctrl+Alt+Del:Ctrl Alt Del:Alt+Tab:Alt Tab" INFO: >>> JWS: EN INFO: >>> JWS: YqJWxUSIiOQzPSSUzLV3m940KqQxIqos000 INFO: >>> JWS: ======== START OF APPLICATION LOGS ======== INFO: >>> JWS: launched process after 405ms: /tmp/mozilla_ylemouel0/jviewer-1.jnlp INFO: >>> JWS: waiting max 60000ms for window to appear... /tmp/mozilla_ylemouel0/jviewer-1.jnlp ERROR: Error: Could not find or load main class

Then I run manually from the tmp directory it works, so there is something wrong when using it via splinter click function. javaws /tmp/mozilla_ylemouel0/jviewer.jnlp

yannlm1 avatar May 29 '18 13:05 yannlm1