이 해결 방법 (파이어 폭스와 크롬에서 테스트)를보십시오 : (그렇지 않으면를 검색 할 수있는 JS 코드를 사용, 텍스트 상자의 ID가 "XYZ"입니다 가정)
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
browser = webdriver.Firefox() # Get local session(use webdriver.Chrome() for chrome)
browser.get("http://www.example.com") # load page from some url
assert "example" in browser.title # assume example.com has string "example" in title
try:
# temporarily make parent(assuming its id is parent_id) visible
browser.execute_script("document.getElementById('parent_id').style.display='block'")
# now the following code won't raise ElementNotVisibleException any more
browser.find_element_by_xpath("//input[@itemcode='XYZ']").send_keys(1)
# hide the parent again
browser.execute_script("document.getElementById('parent_id').style.display='none'")
except NoSuchElementException:
assert 0, "can't find input with XYZ itemcode"
가 다른 해결 방법도 간단하고 아마 텍스트 상자의 값만 변경하려면 다음을 수행하십시오.
browser.execute_script("document.getElementById('XYZ').value+='1'")
감사합니다. 지금은 매력처럼 작동합니다. – vikram
요소에 계속 변경되는 ID가 있으면 어떻게됩니까? 클래스 이름 또는 CSS 선택자로 찾은 다음이를 보이게 할 수 있습니까? –