0

I am trying to automate downloading of some csv files from my Splunk account. We don't have API access unfortunately.

So I thought of using Selenium Python drivers for this.

I installed Selenium and put the chrome driver in the right path.

Now the first page I want to access is the login page of Splunk as below

enter image description here

Here is my initial code in Python using Selenium

import selenium
from selenium import webdriver

PATH= "https://splunk.com/account/login"

driver = webdriver.Chrome()
# Open the website
driver.get(path)


username_box = driver.find_element_by_name('username')

# Get the Password box object 
password_box = driver.find_element_by_name('password')


# Send id information for login
username_box.send_keys(USERNAME)
password_box.send_keys(PASSWORD)

# Click on the sign in button

sign_in_button=driver.find_element_by_link_text('Sign in')
sign_in_button.click()

It works perfectly fine until the sign_in_button driver. So it is able to open the page, enter the user name and password from the user_name and password_element, but when it comes to retrieving the Sign In element object, it's not able to retrieve the object and throws the error:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Sign in"}
  (Session info: chrome=71.0.3578.98)

Here is the HTML of the corresponding Sign In button when I do Inspect on Chrome

enter image description here

So as you see it has only the class and text to it. No name and Id attribute.

So I tried first

driver.find_element_by_link_text('Sign in')

and then

driver.find_element_by_class_name('splButton-primary btn') 

but is not able to retrieve the Sign in button object.

Because of which it's not able to click and login.

Could someone help what is going wrong here with respect to retrieving the Sign in Button?

Thanks

2 Answers 2

2

Sign in is not link text but value attribute, try

driver.find_element_by_css_selector('input[value="Sign in"]')
Sign up to request clarification or add additional context in comments.

2 Comments

Hey quick question. Its a follow up but do u know how u got the above? Because I am trying to find the right selector for a Search button on the next page from css and not able to find the right selector. Pls see the edit.
Hey wud u be able to help with this question? I am facing some issue going further. stackoverflow.com/questions/54154582/…
1

I can't get to that site to try this out, but a couple of ideas... First, your class name included two classes, try using just the one:

driver.find_element_by_class_name('splButton-primary') 

alternatively, try looking for the input specifically:

driver.find_element_by_css_selector('input.splButton-primary')

10 Comments

Thanks. Both work. So mistake was that I was adding both the classes there.
Hey quick question. Its a follow up but do u know how u got the above? Because I am trying to find the right selector for a Search button on the next page from css and not able to find the right selector. Pls see the edit.
Magic? ;-) actually, it's usually straightforward once you understand how CSS Selectors work. for the signin button, I was looking for the thing that made it a unique input element, and that was the class. for your search button, it looks like i want to click on the link with the unique attribute for search: 'a[data-target-view=search' (I didn't use the title attribute because that would change if we're working with a different language)
I used 'a[title="Search"]' and it didn't give the right object
Hey apparently this worked : find_element_by_link_text("Search")
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.