Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Verification for Headless #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions yahooquery/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,42 @@
chrome_options.add_argument("--log-level=3")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--ignore-ssl-errors")
chrome_options.set_capability('pageLoadStrategy', 'eager')

Check warning on line 36 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L35-L36

Added lines #L35 - L36 were not covered by tests
service = Service()
self.driver = webdriver.Chrome(service=service, options=chrome_options)

def login(self):
try:
self.driver.execute_script("window.open('{}');".format(self.LOGIN_URL))
self.driver.execute_script(
"window.open('{}');".format(self.LOGIN_URL))

Check warning on line 43 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L42-L43

Added lines #L42 - L43 were not covered by tests
self.driver.switch_to.window(self.driver.window_handles[-1])
self.driver.find_element(By.ID, "login-username").send_keys(self.username)
self.driver.find_element(By.XPATH, "//input[@id='login-signin']").click()
self.driver.find_element(
By.ID, "login-username").send_keys(self.username)
self.driver.find_element(
By.XPATH, "//input[@id='login-signin']").click()

Check warning on line 48 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L47-L48

Added lines #L47 - L48 were not covered by tests
password_element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.ID, "login-passwd"))
)
password_element.send_keys(self.password)
self.driver.find_element(By.XPATH, "//button[@id='login-signin']").click()
self.driver.find_element(
By.XPATH, "//button[@id='login-signin']").click()

Check warning on line 54 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L53-L54

Added lines #L53 - L54 were not covered by tests

# Yahoo may ask you to verify your login
if not self.driver.find_elements(By.ID, "header-profile-button"):
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located(
(By.CLASS_NAME, "validate-btn"))
)

Check warning on line 61 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L60-L61

Added lines #L60 - L61 were not covered by tests
self.driver.find_elements(
By.CLASS_NAME, "validate-btn")[0].click()
verification_code = input(
"Enter verification code sent to your email or phone number: ")
self.driver.find_element(
By.ID, "verification-code-field").send_keys(verification_code)
self.driver.find_element(

Check warning on line 68 in yahooquery/headless.py

View check run for this annotation

Codecov / codecov/patch

yahooquery/headless.py#L68

Added line #L68 was not covered by tests
By.XPATH, '//*[@id="verify-code-button"]').click()

cookies = self.driver.get_cookies()
self.driver.quit()
self._add_cookies_to_jar(cookies)
Expand Down
Loading