콘셉트를 이해 한 줄 알았는데 ..
HTML 페이지의 탭 목록에서 버튼을 클릭하고 싶습니다.
<div id="subTabs2">
<div id="subTabs">
<ul>
<li>
<a class="currentTab" id="sub_tab_timeclock_today" href="?p=timeclock:today">Today</a>
</li>
<li>
<a id="sub_tab_timeclock_my_timesheet" href="?p=timeclock:my_timesheet">My timesheet</a>
</li>
#list continues ....
내 코드에서 "sub_tab_timeclock_my_timesheet"탭을 클릭하고 싶습니다.
# some code
driver = webdriver.Chrome(driverPath)
driver.get(url)
username = driver.find_element_by_id("user_handle")
password = driver.find_element_by_id("user_password")
username.send_keys("myUser")
password.send_keys("myPass")
driver.find_element_by_class_name("button1").click()
driver.find_element_by_id("sub_tab_timeclock_my_timesheet").click()
로그인 페이지를 통과했지만 ID가 "sub_tab_timeclock_my_timesheet"인 "내 작업 표"탭을 클릭해도 코드가 작동하지 않는 이유를 이해할 수 없습니다.
오류 메시지는 다음과 같습니다.
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="sub_tab_timeclock_my_timesheet"]"}
(Session info: chrome=85.0.4183.83)
내가 도대체 뭘 잘못하고있는 겁니까 ?
감사,
타이밍 문제가 발생한 것 같습니다. driver.find_element_by_class_name("button1").click()
와 사이에 대기를 구현해보십시오 driver.find_element_by_id("sub_tab_timeclock_my_timesheet").click()
.
이렇게하려면 다음과 같이해야합니다.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "sub_tab_timeclock_my_timesheet"))
)
finally:
driver.quit()
.NET 개발자이기 때문에 Python 코드에 대해 잘 모르겠지만이 기사에서 구문 세부 사항을 확인하십시오. https://selenium-python.readthedocs.io/waits.html
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다