I'm writing some code to try to open strava.com and log me in.
from selenium import webdriver
# create a new Chrome webdriver
driver = webdriver.Chrome()
# navigate to the Strava login page
driver.get('https://www.strava.com/login')
# import the time module
import time
time.sleep(3)
# enter your email address and password
email_field = driver.find_element_by_id('email')
email_field.send_keys('Email')
password_field = driver.find_element_by_id('password')
password_field.send_keys('Password')
# click the "Log In" button to log in
login_button = driver.find_element_by_id('login-button')
login_button.click()
# navigate to the explore page
driver.get('https://www.strava.com/explore')
and I get the following error after strava opens and the script ends abruptly.
email_field = driver.find_element_by_id('email')
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
Any ideas?
I've tried to find ways to fix the element but am very new to scripting. I can't seem to make it work and log me into strava.
Related
I have encountered an issue while running my Gatling Script in IntelliJ.
I have multiple scripts to be executed, that involve a login to be executed once, and then the rest of the scripts/flows.
Everything was running fine for the first 4-5 scripts, until I encountered this warning -> " imported Login' is permanently hidden by definition of object Login in package actions" in the newly created script. Ever since, every script, that includes even the previously running scripts, has started throwing this warning. As a result, even if I ignore and go ahead with executing the script, it stops moving ahead and remains stuck, later throwing this blockage in the console as well -> importedLogin' is permanently hidden by definition of object Login in package actions.
I have followed exactly the same scripting practice that I have been doing for the earlier scripts with no deviation from the usual.
Flow:
Execute Login
Capture the session id generated during login action.
Create a new script and import the Login action in that script, thereby using the captured session id value.
The problem arises when I import the Login action packages in my new script, as I start seeing the exception in my newly created script only.
Please help.
Thanks!
//Login Action that is being imported to another action below:
package jda.Scheduler.actions
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
object Login {
def loginAction(): ChainBuilder = {
group("Login") {
exec(http("Main_Request")
.post("/******/****/login?loginName=c***&password=****")
.header("Accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept-Encoding", "gzip")
.header("User-Agent", "okhttp/2.7.5")
.body(StringBody(""""""))
.check(status.in(200))
.check(headerRegex("Set-Cookie", "REFSSessionID(.+?);").find.saveAs("SessionID")))
}
}
}
//Different Action where Login is being imported and issues faced:
package jda.Scheduler.actions
import jda.Scheduler.actions.Login ---> Warning appears (imported 'Login' is permanently hidden by definition of object Login in package actions)
import jda.Scheduler.actions.CreateUserAction ---> Warning appears (imported 'CreateUserAction' is permanently hidden by definition of object CreateUserAction in package actions)
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
object UpdateEmployeeAction {
def updateEmployeeAction(): ChainBuilder = {
group ("updateEmployee"){
exec(http("Main_Request")
.get("/******/****/****/api/***-***/employees/${userID}")
.header("Content-Type", "application/json")
.header("REFSSessionID", "${SessionID}") ---> This part is being captured and saved //in Login action
.body(StringBody("""{
"id": ${userID}, --> This part (${userID}) is being captured and saved in another action, just //like Login Action. Even this is creating same issues.
"badgeNumber": ${userloginname},
"birthDate": "1900-07-31T00:00:00",
"hireDate": "2019-08-12T00:00:00",
"seniorityDate": "2019-08-12T00:00:00",
"minorStatus": "Minor",
"isManagement": false,
"managerPassword": null,
"managerInSchedule": false,
"generateException": true,
"generateAlerts": true,
"canWorkUnassignedJobs": true,
"schedulingTypeCode": "Manual",
"ignoreBiometricValidation": false,
"punchValidationCode": "NoScheduleValidation"
}"""))
.check(status.in(200))
)}}
}
I have just installed Moodle on my web-server. Everything was OK until I came to page where I saw this text: "This page should automatically redirect. If nothing is happening please use the continue link below. Continue."
When I click on Continue, the same page shows again. I deleted all data from moodledata folder (saw it on this site), but I have the same problem again and again. What can be a problem here and how to solve it?
Thank you in advance.
The first step to do is to enable debugging. I assume you can not access site administration anymore so you have to enable debugging in the config.php file. The file is located in /path/to/moodle/config.php (that means in the root folder of your Moodle installation).
The first lines should look like that in config.php. That means you have to add the 4 lines which are under $CFG = new stdClass();
<?php // Moodle configuration file
unset($CFG);
global $CFG;
$CFG = new stdClass();
#error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS!
#ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS!
$CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!
$CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS!
After that open Moodle in your browser. A debug message will be displayed. Post the error message in order to get additional help so solve the problem.
I am trying to schedule an R script to run, using rtweet to hit the Twitter API and then using RPOSTgreSQL to load the data into a table once a day.
I was able to successfully use taskscheduleR to create the task. However, when it runs I get an error that says...
<credentials> oauth_token, oauth_token_secret
---
Requesting token on behalf of user...
Error: API user token required. see http://rtweet.info/articles/auth.html for instructions
Execution halted
Here is my entire code with a few things masked due to API credentials and database info, passwords, etc
#load all packages
library(rtweet)
library(sqldf)
library(dplyr)
library("RPostgreSQL")
#connect to Twitter API
create_token(
app = "masked for stack",
consumer_key = "masked for stack",
consumer_secret = "masked for stack",
access_token = "masked for stack",
access_secret = "masked for stack")
## get user IDs of accounts following
followers=get_followers("masked for stack", n = 1000)
## lookup data on those accounts
followers_data=lookup_users(followers$user_id)
#add the date of the run
followers_data$date=Sys.Date()
#extract columns
twitter_followers=dplyr::select(followers_data,"date","screen_name","name","location","description","followers_count",
"friends_count","listed_count","statuses_count","favourites_count","verified")
# create a connection
# save the password that we can "hide" it as best as we can by collapsing it
pw <- {
"masked for stack"
}
# loads the PostgreSQL driver
drv <- dbDriver("PostgreSQL")
# creates a connection to the postgres database
# note that "con" will be used later in each connection to the database
con <- dbConnect(drv, dbname = "masked for stack",
host = "localhost", port = 5432,
user = "postgres", password = pw)
rm(pw) # removes the password
# writes df to the PostgreSQL database
dbWriteTable(con, "twitter_followers",
value = twitter_followers, append = TRUE, row.names = FALSE)
My code runs perfectly fine doing everything on my own manually. It seems that rtweet doesn't like getting ran by windows scheduler.
Any ideas? `
So after hours of digging I figured out that something was not working well with the scheduleR app. It may have been creating a task in windows scheduler that wouldn't run when my laptop was on AC power I'm not sure. Either way I did a workaround like this.
Created a text file and saved as a .bat extension with the following format:
"C:\Program Files\R\R-3.5.2\bin\x64\R.exe" CMD BATCH file_location.R
From there I scheduled in Windows scheduler. Make sure you go through all the options and don't choose a basic task. If you do a basic one you may not allow it to run on laptop battery power.
I was trying out this Python code from a training website in IPython:
from bs4 import BeautifulSoup
import requests
url = raw_input("www.google.com")
r = requests.get("http://" +url)
data = r.text
soup = BeautifulSoup(data)
for link in soup.find_all('a'):
print(link.get('href'))
and found that it ran fine on the first try. I've now tried simply restarting the kernel, opening a new notebook, and generally returning the settings to how they were when I first ran the program with no luck. Why might IPython be failing to run the code and giving no response at all (as though I haven't clicked anything)?
Seems like raw_input is not supported by IPython. So it's probably just hanging there. If you change:
url = raw_input("www.google.com")
to
url = "www.google.com"
it should work.
When you perform the same analysis in a notebook on different data files, may be handy to graphically select a data file.
In my python scripts I usually implement a QT dialog that returns the file-name of the selected file:
from PySide import QtCore, QtGui
def gui_fname(dir=None):
"""Select a file via a dialog and return the file name.
"""
if dir is None: dir ='./'
fname = QtGui.QFileDialog.getOpenFileName(None, "Select data file...",
dir, filter="All files (*);; SM Files (*.sm)")
return fname[0]
However, running this function from an notebook
full_fname = gui_fname()
causes the kernel to die (and restart):
Interestingly, puttying this 3 command in 3 separate cells works
%matplotlib qt
full_fname = gui_fname()
%matplotlib inline
but when I put those commands in one single cell the kernel dies again.
This prevents to create a function like gui_fname_ipynb() that transparently allows selecting a file with a GUI.
For convenience, I created a notebook illustrating the problem:
Open/select file with GUI (Qt Dialog)
Any suggestion on how to execute a dialog for file selection from within an IPython Notebook?
Using Anaconda 5.0.0 on windows (Python 3.6.2, IPython 6.1.0), the following two options are both working for me.
OPTION 1: Entirely in a Jupyter notebook:
CELL 1:
%gui qt
from PyQt5.QtWidgets import QFileDialog
def gui_fname(dir=None):
"""Select a file via a dialog and return the file name."""
if dir is None: dir ='./'
fname = QFileDialog.getOpenFileName(None, "Select data file...",
dir, filter="All files (*);; SM Files (*.sm)")
return fname[0]
CELL 2:
gui_fname()
This is working for me but it seems a bit...fragile. If I combine these two things into the same cell, it crashes. Or if I omit the %gui qt, it crashes. If I "restart kernel and run all cells", it doesn't work. So I kinda like this other option...
MORE RELIABLE OPTION: Separate script that opens dialog box in a new process
(Based on mkrog code here.)
PUT THE FOLLOWING IN A SEPARATE PYTHON SCRIPT CALLED blah.py:
from sys import executable, argv
from subprocess import check_output
from PyQt5.QtWidgets import QFileDialog, QApplication
def gui_fname(directory='./'):
"""Open a file dialog, starting in the given directory, and return
the chosen filename"""
# run this exact file in a separate process, and grab the result
file = check_output([executable, __file__, directory])
return file.strip()
if __name__ == "__main__":
directory = argv[1]
app = QApplication([directory])
fname = QFileDialog.getOpenFileName(None, "Select a file...",
directory, filter="All files (*)")
print(fname[0])
...AND IN YOUR JUPYTER NOTEBOOK
import blah
blah.gui_fname()
I have a universal code where it does its job without any problem. Here is my sugestion:
try:
from tkinter import Tk
from tkFileDialog import askopenfilenames
except:
from tkinter import Tk
from tkinter import filedialog
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filenames = filedialog.askopenfilenames() # show an "Open" dialog box and return the path to the selected file
print (filenames)
hope it can be useful
This behaviour was a bug in IPython:
https://github.com/ipython/ipython/issues/4997
that was fixed here:
https://github.com/ipython/ipython/pull/5077
The function to open a gui dialog should work on current master and on the oncoming 2.0 release.
To date, the last 1.x version (1.2.1) does not include a backport of the fix.
EDIT: The example code still crashes IPython 2.x, see this issue.