파이어 폭스에서 파이어 버그를 사용하여 ID가 할당되지 않은 링크의 xpath를 얻었습니다. 링크는 이미지가있는 실제 자바 스크립트 링크입니다. 이 링크를 클릭하고 싶지만 작동하지 않습니다.셀레늄 파이썬에서 xpath 사용
실제 xpath는 '/html/body/div [2]/div/div/div [3]/div/div/table/tbody/tr [1]/TBODY/TR [1]/TD/DIV [1]/DIV/표/THEAD/TR [2]/[1]/A/IMG '
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
URL = 'http://example.com'
driver.set_window_size(1024, 768)
driver.get(url)
link = driver.find_element_by_xpath(//*[@id="//html/body/div[2]/div/div/div[3]/div/div/table/tbody/tr[1]/td[2]/form/table/tbody/tr[1]/td/div[1]/div/table/thead/tr[2]/th[1]/a/img"])
for link in links:
link.click()
난 다음 오류 얻을 : 제 is either invalid or does not result in a WebElement. The following error occurred:\nInvalidSelectorError: Unable to locate an element with the xpath expression //*[@id=/html/body/div[2]/div/div/div[3]/div/div/table/tbody/tr[1]/td[2]/form/table/tbody/tr[1]/td/div[1]/div/table/thead/tr[2]/th[1]/a/img because of the following error:\n[Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: "<unknown>"]' ; Stacktrace:
<a onclick="if(typeof functionx == 'function'){functionx(document.getElement…,'liststuff','');}return false" href="#">
<img style="border: 0px;" onmouseover="this.src='/add-hover.gif';" onmouseout="this.src='/add.gif';" alt="Add" src="/icon-add.gif"></img>
</a>
링크가 포함 된 관련 html 코드를 표시 하시겠습니까, 아니면 웹 사이트에 대한 링크를 제공 할 수 있습니까? 감사. – alecxe
@alecxe 죄송합니다. 회사의 내부 서버에 있기 때문에 URL을 제공 할 수 없습니다. – user2242044
추측 : ''태그는 중첩 된'' 태그 대신에 'img' 속성을 가질 수 있습니다. 사실이라면 XPath가 끝날 때'a/img '를'a/@ img'로 변경해보십시오. – unutbu