나는 오른쪽 상단 모서리에있는 https://www.pcfinancial.ca/의 드롭 다운 메뉴에서 두 번째 옵션을 선택하는 데 도움이되는 프로그램 작업을하고 있습니다. 여기에 지금까지 내 코드입니다 :Python Selenium을 사용하여 요소를 클릭 할 수 없습니다.
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import ui
driver = webdriver.Chrome()
driver.get('https://www.pcfinancial.ca/');
driver.find_element_by_xpath('//*[@id="lnkSignInOp"]').click() #click on dropdown menu - working
driver.find_element_by_xpath('//*[@id="PCM"]/a').click() #select "pc mastercard" - not working
어떤 이상한 것은 내가 처음 driver.find_elements_by_xpath(...)
줄을 사용하여 드롭 다운 메뉴에 액세스 할 수 있습니다,하지만 두 번째 옵션을 선택할 때 나는 다음과 같은 오류가 발생합니다.
Traceback (most recent call last):
File "C:\Users\Imad\Documents\Programming\Python\test.py", line 10, in <module>
driver.find_element_by_xpath('//*[@id="PCM"]/a').click() #open up dropdown menu works
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 501, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.16299 x86_64)
아무도 나에게 무슨 일이 일어나고 있고 어떻게 해결할 수 있는지 이해할 수 있습니까? 미리 감사드립니다!
감사합니다. 웹 페이지가 실제로로드 된 후 대기 시간이 필요하다는 것을 알지 못했습니다. WebDriverWait에 관해서는, 당신은 10 단위가 무엇인지 알고 있습니까? 그냥 호기심을 불러서 다음번에 "너무 길다"라는 것을 알고 있습니다. –
@ImadKalboneh 문제 없습니다. 다행입니다. 10은 "초"입니다. 감사합니다. – alecxe