1

I want to use selenium to automate the process from open a specific website to log in to search for particular articles. Few of the steps I could do it but facing error in 'sign in' step.

from selenium import webdriver
from selenium.webdriver.common.by import By
base = 'https://www.wsj.com'
url = 'https://www.wsj.com/search/term.html?KEYWORDS=cybersecurity&min-date=2018/04/01&max-date=2019/03/31&isAdvanced=true&daysback=90d&andor=AND&sort=date-desc&source=wsjarticle,wsjpro&page=1'

browser = webdriver.Safari(executable_path='/usr/bin/safaridriver')
browser.get(url)
browser.find_element_by_id('editions-select').click()
browser.find_element_by_id('na,us').click()
browser.find_element(By.XPATH, '//button[@type="button"],[contain(.,"Sign In")]').click()
browser.find_element_by_id('username').send_keys('**#&^&@$@#$')
browser.find_element_by_id('password').send_keys('@#@$%%**')
browser.find_element_by_id('basic-login').click()
browser.find_element_by_id('masthead-container').click()
browser.find_element_by_id('searchInput').send_keys('cybersecurity')
browser.find_element_by_name('ADVANCED SEARCH').click()
browser.find_element_by_id('dp1560924131783').send_keys('2018/04/01')
browser.find_element_by_id('dp1560924131784').send_keys('2019/03/31')
browser.find_element_by_id('wsjblogs').click()
browser.find_element_by_id('wsjvideo').click()
browser.find_element_by_id('interactivemedia').click()
browser.find_element_by_id('sitesearch').click()

The code is working till this line:

browser.find_element_by_id('na,us').click()

But after that it is showing error in this line:

browser.find_element(By.XPATH, '//button[@type="button"],[contain(.,"Sign In")]').click()

The error message says​:

selenium.common.exceptions.InvalidSelectorException: Message: 

What is wrong is my code?

1 Answer 1

1

This error message...

selenium.common.exceptions.InvalidSelectorException

...implies that the XPath expression was not a valid one.

However, it seems you were close. You need to replace:

'//button[@type="button"],[contain(.,"Sign In")]'

and join the two condition with and operator as follows:

"//button[@type='button' and contains(.,'Sign In')]"
Sign up to request clarification or add additional context in comments.

2 Comments

Not working. The same line is giving an error but this time the error is different selenium.common.exceptions.NoSuchElementException
@PiyushGhasiya NoSuchElementException is a different error all together where as your current issue was InvalidSelectorException. Feel free to raise a new question as per your new requirement. StackOverflow volunteers will be happy to help you out.

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.