0

I have most of the code working for this now im just looking for selenium to get a console.log from Chrome

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://192.168.0.3:3333/")
time.sleep(1)

for entry in driver.get_log('browser'):
    print entry
print

The problem im getting is 'webdriver' has no attribute 'get_log()' I have tried using 'driver.ChromeOptions.get_log()' but no attribute ChromeOptions.

im a little lost with this module as i have tried example code with the same results.

14
  • Are you looking for something like this: stackoverflow.com/questions/22087881/… Commented Jul 11, 2015 at 21:35
  • not exactly. I just want to have a button on a html page that when clicked will input the word "hello" into an active notepad document that's being edited. Its basically a hotkey function but made with JavaScript Commented Jul 11, 2015 at 23:38
  • 1
    For security reasons javascript does not have access to what is installed or running on your computer. because you mentioned you want to stick to the windows machine, what you want to do can best be done by developing an activex. you'll also have some limitations in it, but I think that's as far as you can go by accessing clients resources. Commented Jul 12, 2015 at 1:36
  • this is proving to be a difficult project. from what iv seen Activex does not run on mac or linux. Having cross platform support for this is a must. if the js or other scripting language can access an application of some sort to forward on the strings (like an virtual keyboard application) could that be done ? Commented Jul 12, 2015 at 2:29
  • 1
    @ScottPaterson, as far as I know, no client-side scripting language is able to do so. just imagine if it was doable, what would hackers do to poor clients computer! Commented Jul 12, 2015 at 3:35

1 Answer 1

0

I finally got it working. Rather than using console.log i used the value of a div and use a onclick js function so set value to "key1", then another js function to clear the value on a 250ms delay. (looking for a better way of doing this.)

function jsfun1() {
document.getElementById('keyvalue').value = 'Key Press 1';
}

The selenium code basically checks the value of the div and prints it ever 0.1 seconds.

d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome()
driver.get("http://192.168.0.3:3333/")
while True:
    time.sleep(0.1)
    elem = driver.find_element_by_id('keyvalue')
    abc = elem.get_attribute("value")
    print (abc)
    time.sleep(0.1)
    shell.SendKeys(abc, 0)
    driver.execute_script("document.getElementById('keyvalue').value = ''")

EDIT: Refined code to work much nicer, registering ever button press rather than a time delay.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.