【发布时间】:2021-04-24 02:39:03
【问题描述】:
我有文字:
var1 = 'ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"'
我有 xpath:
driver.find_element_by_xpath("//a[text()='"+var1+"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']").click() - 不行
//a[text()='ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить'] - 但是这个工作!
Python 给我写信:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[text()='ТСЖ "ВОЛГОГРАДСКИЙ ПР-Т 50-1, 52-1, 52-2, 56-1, 56-2, 58-1, 58-3, 60-2, 64-1, 64-2, 66-2, ВОЛЖСКИЙ 21"']/ancestor::div[contains(@class,'chakra-stack') and contains(@class,'css-1oap1wr')]/following-sibling::div/descendant::button[text()='Отклонить']"}
但是,如果我从错误消息中剪切 xpath 并将其像 xpath 一样放在 Chrome 的控制台中 - 会找到元素。
元素绝对可见且已加载。 对不起我的英语。
【问题讨论】:
-
您需要正确转义引号。您的问题/代码有点难以阅读,所以我无法给出确切的答案。
标签: python selenium google-chrome selenium-chromedriver quotes