请帮我解决这个问题,我无法选中python3和硒复选框。
这是错误消息
selenium.common.exceptions.ElementNotInteractableException:消息: 元素无法滚动到视图中
链接到geckodriver https://github.com/mozilla/geckodriver/releases
-此处的代码---
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from bs4 import BeautifulSoup
import re
import pandas as pd
import os
url = "https://partner.ingatlan.com/zalabanyi.rezso"
driver = webdriver.Firefox(executable_path='/Users/Test/Desktop/geckodriver')
driver.implicitly_wait(30)
driver.get(url)
python_button = driver.find_element_by_id('btn-contact-email')
python_button.click()
search_input_box = driver.find_element_by_id("contact_message_name")
search_input_box.send_keys("John Doe")
find_phone = driver.find_element_by_id("contact_message_phoneNumber")
find_phone.send_keys("00447455555")
find_email = driver.find_element_by_id("contact_message_email")
find_email.send_keys("noreply@email.com")
find_message = driver.find_element_by_id("contact_message_message")
find_message.send_keys("This is my message for you")
find_agree = driver.find_element_by_id("contact_message_acceptPrivacyPolicy")
driver.implicitly_wait(10)
find_agree.click()
答案 0 :(得分:0)
您可以使用JavaScript选中复选框:
driver.execute_script("arguments[0].click();", driver.find_element_by_id("contact_message_acceptPrivacyPolicy"))
另一种方法是使用Actions
单击标签:
from selenium.webdriver.common import action_chains
...
checkbox = driver.find_element_by_css_selector("label[for='contact_message_acceptPrivacyPolicy']")
action = action_chains.ActionChains(driver)
action.move_to_element_with_offset(checkbox, 1, 1).click().perform()