1

I am trying 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' and contains(.,'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' and contains(.,'Sign In')]").click()

The error message says:

selenium.common.exceptions.NoSuchElementException

What should I do to make it work? What is the problem?

1
  • 1
    the locators you have here don't appear on the website... Commented Jun 19, 2019 at 8:34

1 Answer 1

2

You should use WebDriverWait:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait

botton_to_click = WebDriverWait(driver, 10).until(EC.element_to_be_clickable, ((By.XPATH,"//button[@type='button' and contains(.,'Sign In')]")))
botton_to_click.click()

Hope this helps you!

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

6 Comments

contains(.,'Sign In') is perfect where as I feel contains(text(),'Sign In') is not optimized.
Not working. Showing error in line button_to_click.click() Error is: AttributeError: 'element_to_be_clickable' object has no attribute 'click'
No. Error: TypeError: 'tuple' object is not callable
@PiyushGhasiya Sorry I'm not on PC so it's hard to fix typoes... one moment I fixed it I am sorry for the inconvenience...
Again error. Showing error in line botton_to_click() Error is AttributeError: 'element_to_be_clickable' object has no attribute 'click'
|

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.