2021. 8. 31. 18:45ㆍPython
성신여대 학생임을 확인하는 기능을 구현
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import sys
from selenium import webdriver
from selenium.common.exceptions import ElementNotInteractableException
# 인증 정보 (개인정보라서 내용은 비워둠)
NAME =
BIRTH_YEAR =
BIRTH_MONTH =
BIRTH_DATE =
# firefox 모듈의 WebDriver 객체를 생성한다.
driver = webdriver.Firefox()
def main():
# 인증 결과를 저장한다.
is_ssAuthorized = False
# 로그인 페이지를 엽니다.
print('Accessing to sign in page ...', file=sys.stderr)
driver.get('https://portal.sungshin.ac.kr/sso/login.jsp')
# 로그인 페이지에 들어가졌는지 확인한다.
# title 요소의 텍스트가 일치하지 않으면 AssertionError 예외가 발생한다.
assert ':: 성신여자대학교 포탈시스템::' in driver.title
driver.find_element_by_link_text('아이디찾기').click()
str_name = "(document.getElementsByName('srchUserNm'))[1].value = '" + NAME + "'"
str_year = "(document.getElementsByName('year'))[0].value = '" + str(BIRTH_YEAR) + "'"
str_month = "(document.getElementsByName('month'))[0].value = '" + str(BIRTH_MONTH) + "'"
str_date = "(document.getElementsByName('day'))[0].value = '" + str(BIRTH_DATE) + "'"
driver.execute_script(str_name)
driver.execute_script(str_year)
driver.execute_script(str_month)
driver.execute_script(str_date)
select = driver.find_element_by_css_selector('select[name="identSel"]')
driver.execute_script('var select = arguments[0];' +
'for(var i = 0; i < select.options.length; i++) {' +
' if(select.options[i].text == arguments[1]){' +
'select.options[i].selected = true; } }'
,select, '핸드폰')
# ID 찾기의 '확인' 버튼을 누른다.
# 학생 정보가 등록되어 있지 않은 경우에만 '등록된 아이디가 없습니다.학사지원팀에 문의해주세요.' 창이 표시된다.
driver.find_element_by_css_selector('a[href="javascript:findUserChk();"]').click()
try:
# '등록된 아이디가 없습니다.학사지원팀에 문의해주세요.' 창의 '확인' 버튼을 누른다.
driver.find_element_by_id('certfId').click()
except ElementNotInteractableException: # 학생이 맞을 경우 해당 예외가 발생한다.
print('Error: ElementNotInteractableException', file=sys.stderr)
print('Authorized', file=sys.stderr)
is_ssAuthorized = True
except BaseException as e: # 그 외의 예외가 발생한 경우
print('Error: ', type(e), file=sys.stderr)
else:
print('not Authorized', file=sys.stderr)
finally:
# closes current window on which Selenium is running automated tests.
driver.close()
# 인증 결과를 반환한다.
return is_ssAuthorized
main()
|
cs |
[ 참고한 자료 ]
Locating multiple elements in Selenium Python - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org
[python] Python을 사용하여 Selenium으로 드롭 다운 메뉴 값을 선택하는 방법은 무엇입니까? - 리뷰나
드롭 다운 메뉴 에서 요소를 선택해야 합니다. 예를 들면 다음과 같습니다.
https://stackoverflow.com/questions/58001380/selenium-is-not-reachable-by-keyboard
selenium: is not reachable by keyboard
I try to publish gist on gist.github.com using python/selenium, This is my current code : driver.find_element(By.NAME, "gist[contents][][name]").send_keys("file.md") #import pdb; pdb.set_trace()...
stackoverflow.com
https://www.onooks.com/selenium-is-not-reachable-by-keyboard/
Org open qi selenium Element Not Interact able Exception Element is not reachable by keyboard while sending text to First Name f
The error is : The code is: ElementNotInteractableException: Element is not reachable by keyboard Element is not reachable by keyboard in plain words means that the element can’t be reached using the keyboard, which means you won’t be physically inter
www.onooks.com
https://stackoverflow.com/questions/7794087/running-javascript-in-selenium-using-python
Running javascript in Selenium using Python
I am totally new to Selenium. I want to execute a javascript snippet in the following code(as commented in the code), but can't do so. Please help. from selenium import webdriver import selenium f...
stackoverflow.com
How to use execute_script in python and selenium to select a value from drop down
I have a form whose elements return elementnotinteractable exception when I use selenium operations like click() and sen_keys. I used execute_script to interact with elements and it works fine. Ho...
stackoverflow.com
https://stackoverflow.com/questions/38232406/selenium-in-python-selecting-an-option
Selenium in Python: Selecting an Option
I am having no luck selecting an option from a
[ geckodriver 설치 방법 (firefox) ]
https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu
How to install geckodriver in Ubuntu?
I use Selenium in Python, I tried to run the webdriver function: default_browser = webdriver.Firefox() This Exception: WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
askubuntu.com
'Python' 카테고리의 다른 글
Selenium (0) | 2021.10.15 |
---|---|
python mariadb (0) | 2021.09.11 |
conda 에서 robobrowser, selenium 설치하기 (0) | 2021.08.28 |
python 2 설치 (0) | 2021.08.21 |
바이트 형 (bytes) (0) | 2021.07.23 |