- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经问过一个与此类似的问题,但它是不同的。
仍然不明白为什么 find_elements
不像 selenium 文档那样工作 :(。
from bs4 import BeautifulSoup as soup
import requests
import sys
import re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
input("If ready press 'enter'")
loginurl = 'https://www.willhaben.at/iad/?islogout=true&logoff.y=10'
chrome_options = Options()
chrome_options.add_argument('disable-infobars')
driver = webdriver.Chrome(executable_path="C:\\Users\\laure\\Downloads\\chromedriver_win32\\chromedriver.exe", chrome_options=chrome_options, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
USERNAME = 'notgonnagiveit :)'
PASSWORD = 'notgonnagiveit'
driver.get(loginurl)
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="username"]'))
)
username = driver.find_element_by_xpath('//input[@id="username"]')
password = driver.find_element_by_xpath('//input[@id="password"]')
password.send_keys(PASSWORD)
username.send_keys(USERNAME)
for i in range(input("Number of products to reactivate: ")):
driver.get("https://www.willhaben.at/iad/myprofile/adadministration/showlist?page=6")
driver.find_element_by_xpath("//a[@class='btn icon-icon_bearbeiten status-expired' and starts-with(@id,'editAdLink-')]").click()
driver.quit()
我正在尝试单击具有 type=button
的链接但标签是<a>
.
现在它第一次工作了,但以后就不行了。
这是错误:
Traceback (most recent call last):
File "D:\OneDrive\Dokumente\Willhaben\Willhaben.py", line 85, in <module>
editbutton = driver.find_element_by_xpath("//input[@class='btn icon-icon_bearbeiten status-expired'][@type='button']")
File "C:\Users\laure\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 368, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\laure\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 858, in find_element
'value': value})['value']
File "C:\Users\laure\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "C:\Users\laure\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@class='btn icon-icon_bearbeiten status-expired'][@type='button']"}
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 10.0.16299 x86_64)
html代码:
<div class="pull-right edit">
<a id="editAdLink-225585118" rel="nofollow" class="btn icon-icon_bearbeiten status-expired" title="Bearbeiten" onclick="IADLIB.tealium.trackClickEvent({"tmsData":{"user_role_id":"0","environment":"web","user_email":"firstname.lastname%40live.co.uk","user_is_c2c":"true","page_type":"My_Ads","user_id":"29268370","user_name":"firstname","event_name":"my_ads","user_gender":"0"}}, "N", "my_ads_edit")
" href="/iad/myprofile/editad?adId=225585118&page=6" type="button">
</a>
</div>
最佳答案
根据您共享的 HTML
点击 link
您可以使用以下代码行:
driver.find_element_by_xpath("//a[@class='btn icon-icon_bearbeiten status-expired' and starts-with(@id,'editAdLink-')]").click()
关于python - 在 python 中使用 selenium 单击链接(<a> 标记,type=button)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47928440/
我遇到过这个 html: 上面的html和这个有什么区别: 最佳答案 来自MDN page on the tag : 对于 type 的属性标签,可能的值是: 提交:按钮将表单数据提交给服务器
Button button= (Button) findViewbyID(R.id.button); 和 Button button = new Button(this); 有什么区别? 最佳答案 有
我是一名优秀的程序员,十分优秀!