我怎么可能使这段代码工作…我最近一直想弄明白。但我的代码似乎不工作这里是代码,我已经尝试了按钮::之前…当我输入或添加图像时,发送按钮将出现。Sendkey。
我试过的代码
xpath = '/html/body/div[1]/div/div[1]/div/main/div[1]/div/div/div/div[1]/div/div/div[3]/form/button'
WebDriverWait(self.browser, self.delay).until(
EC.presence_of_element_located((By.XPATH, xpath)))
send = self.browser.find_element(By.XPATH, value=xpath)
send.click()
I got this errors
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdriversupportwait.py", line 95, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
Backtrace:
(No symbol) [0x00FAF243]
(No symbol) [0x00F37FD1]
(No symbol) [0x00E2D04D]
(No symbol) [0x00E5C0B0]
(No symbol) [0x00E5C22B]
(No symbol) [0x00E8E612]
(No symbol) [0x00E785D4]
(No symbol) [0x00E8C9EB]
(No symbol) [0x00E78386]
(No symbol) [0x00E5163C]
(No symbol) [0x00E5269D]
GetHandleVerifier [0x01249A22+2655074]
GetHandleVerifier [0x0123CA24+2601828]
GetHandleVerifier [0x01058C0A+619850]
GetHandleVerifier [0x01057830+614768]
(No symbol) [0x00F405FC]
(No symbol) [0x00F45968]
(No symbol) [0x00F45A55]
(No symbol) [0x00F5051B]
BaseThreadInitThunk [0x7753FEF9+25]
RtlGetAppContainerNamedObjectPath [0x77AF7BBE+286]
RtlGetAppContainerNamedObjectPath [0x77AF7B8E+238]
这种形式的xpath不可靠,更改它可以解决您的问题。假设"Before"或";Send"如果在按钮上写入文本,则可以尝试xpath:
xpath = "//*[.='Before']"
或
xpath = "//*[.='Send']"
如果这不起作用,检查你的页面,寻找CSS元素,如ID或class。(要查看页面代码:右键单击"检查",将焦点放在元素上,再次右键单击"检查"元素(按钮))如果看到类或id,请将它们作为XPath使用:
xpath = "//*[@id='example-text']"
xpath = "//*[@class='put-your-class-string-here']"
如果这不能解决问题,你能分享更多关于你试图与之交互的页面元素的信息吗?或者只是按钮的HTML代码