输入代码,单击标签,然后使用 Python Selenium 单击按钮
我有兴趣在搜索栏中输入代码,单击标签,最后单击按钮。具体来说,该页面是 https://www.icribis.com/it/。我必须在搜索栏中输入代码(其中出现消息“Inserisci i dati dell'azienda”),然后我必须单击标签“Codice Financiale”(在搜索栏下方),最后单击带有放大镜。我的尝试:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
url = 'https://www.icribis.com/it/'
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
driver.get(url)
time.sleep(2)
# Disable cookies
driver.execute_script('return document.querySelector("#usercentrics-root").shadowRoot.querySelector("#uc-center-container > div:nth-child(2) div > button:nth-child(3)")').click()
# Enter the code
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class,'clearfix')]//input[@name='search']"))).send_keys("my_code")
# Click on the label
# ...
# Click on the button with the magnifying glass
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class,'media-obj-right')]//input[@type='submit']"))).click()
如何点击标签?另外两行是正确的吗?
I am interested in entering a code in a search bar, clicking on a label and finally clicking on a button. Specifically, the page is https://www.icribis.com/it/. I have to enter the code in the search bar (where the message "Inserisci i dati dell'azienda" appears), then I have to click on the label "Codice fiscale" (under the search bar) and finally click on the button with the magnifying glass. My attempt:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
url = 'https://www.icribis.com/it/'
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
driver.get(url)
time.sleep(2)
# Disable cookies
driver.execute_script('return document.querySelector("#usercentrics-root").shadowRoot.querySelector("#uc-center-container > div:nth-child(2) div > button:nth-child(3)")').click()
# Enter the code
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class,'clearfix')]//input[@name='search']"))).send_keys("my_code")
# Click on the label
# ...
# Click on the button with the magnifying glass
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class,'media-obj-right')]//input[@type='submit']"))).click()
How can I click on a label? And the other two lines are correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此 xpath:
没有任何匹配项,您应该使用此 id:
或 XPath:
代码:
或
Update1 with ID, < strong>CSS_SELECTOR:
使用Xpath更新2:
如果您只想拥有基于XPath的解决方案:
This xpath:
does not have any match, you should use this id:
or XPath:
Code:
or
Update1 with ID, CSS_SELECTOR:
Update2 with Xpath:
If you want to have only XPath based solution:
而不是这个 XPath 定位器
您可以使用这个
另外这个 XPath 不是唯一的
尝试使用
代替
所以你的代码可能是:
instead of this XPath locator
You can use this
Also this XPath is not unique
Try using
Instead
So your code could be: