0
votes

I'm trying to make this python script work:

import json
import time

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote import switch_to
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By


def read_configuration_file():
    with open('config.json') as file:
        arguments = json.load(file)
    return arguments

def login(driver, email, password):
    driver.get('https://login.globo.com/login/1')

    email_input = driver.find_element_by_name('login')
    password_input = driver.find_element_by_name('password')
    form = driver.find_element_by_id('login-form')

    email_input.send_keys(email)
    password_input.send_keys(password)
    form.submit()

def click_on_target(driver, target):
    driver.find_elements_by_class_name('inCORyOvohT4oJQIoKjlO')[target - 1].click()


def click_on_captcha(driver):
    driver.find_element_by_class_name('gc__3_EfD').click()


arguments = read_configuration_file()

print("You're voting on", arguments['targetPosition'])

driver = webdriver.Edge(executable_path=arguments['webDriverPath'])
driver.implicitly_wait(8)

login(driver, arguments['credentials']['username'],
      arguments['credentials']['password'])

driver.get(arguments['pollURL'])

correct_votes = 0
while True:
    click_on_target(driver, arguments['targetPosition'])
    click_on_captcha(driver)
    time.sleep(5)
    if not driver.find_element_by_class_name('_1iMqGq8UKv9W1nDF0AvZbu').is_displayed():
        click_on_captcha(driver)
    else:
        correct_votes += 1
        print(correct_votes, 'computed')
        driver.get(arguments['pollURL'])
    time.sleep(5)

driver.close()

the JSON file:

{
    "pollURL": "",
    "targetPosition": 1,
    "credentials": {
        "username": "",
        "password": ""
    },
    "webDriverPath": "C:/Users/ticer/Documents/bbbvoter/msedgedriver.exe"
}

But I keep getting the same error:

("You're voting on", 1)
Traceback (most recent call last):
  File "voter.py", line 41, in <module>
    driver = webdriver.Edge(executable_path=arguments['webDriverPath'])
  File "/home/tiberio/.local/lib/python2.7/site-packages/selenium/webdriver/edge/webdriver.py", line 56, in __init__
    self.edge_service.start()
  File "/home/tiberio/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'msedgedriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687

I downloaded the edge webdriver Version: 82.0.459.1 x64, the .exe is on the same folder as the script, I don't know what else to do to make it work, any ideas? What does it mean when it says it needs in PATH? thanks :)

2
Try to copy the entire folder location where msedgedriver.exe is saved,open the System Properties window and click the Environment Variables menu.In System variables section, select the Path variable (highlighted in red in the above image) and click on Edit button. Then add the location of the webdriver to path variable.After that, click OK and try to run your code.Zhi Lv
Besides, since you are using the 82.0.459.1 x64 version webdriver, it seems that you are using the Microsoft Edge Insider Channels version, please check the Microsoft Edge version to make sure the webdriver version and browser version are matches. And I think perhaps you need set the Binary Location property to set the browser start item. You could refer to this article (this article is C# code).Zhi Lv

2 Answers

1
votes

As per the exception, the program is expecting the driver to available in System PATH. To add the driver location to PATH, please follow the below step.

In Windows, goto System -> Advanced System Settings -> Advanced (Tab) -> Environment Variables (button):

enter image description here

Under System variables, scroll to the Variable named Path -> Edit… (button) -> Variable value -> Scroll to the end of the field, add a semicolon and append the local path of you webdriver ("C:/Users/ticer/Documents/bbbvoter/msedgedriver.exe")

System Properties

0
votes

Add a double backslash (//) in your driver path or make it raw string

"webDriverPath": r"C:/Users/ticer/Documents/bbbvoter/msedgedriver.exe"