Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yannlm1 opened this issue May 4, 2018 · 14 comments
Closed

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

yannlm1 opened this issue May 4, 2018 · 14 comments
Labels

Comments

@yannlm1
Copy link

yannlm1 commented May 4, 2018

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

@andrewsmedina
Copy link
Member

@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.

@yannlm1
Copy link
Author

yannlm1 commented May 7, 2018

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()

@andrewsmedina
Copy link
Member

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
Copy link
Member

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()

@yannlm1
Copy link
Author

yannlm1 commented May 8, 2018

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"

@andrewsmedina
Copy link
Member

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

@yannlm1
Copy link
Author

yannlm1 commented May 8, 2018

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.

@andrewsmedina
Copy link
Member

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?

@yannlm1
Copy link
Author

yannlm1 commented May 9, 2018

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,

@andrewsmedina
Copy link
Member

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

@yannlm1
Copy link
Author

yannlm1 commented May 17, 2018

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
Copy link
Author

yannlm1 commented May 28, 2018

Hello Andrew,

Could you please have a look to my question?

Thanks.

@andrewsmedina
Copy link
Member

I don't know how to do it :(

@yannlm1
Copy link
Author

yannlm1 commented May 29, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants