我有一个从https://www.carecredit.com/doctor-locator/抓取数据的小任务。 我无法使用我的脚本执行复选框勾选。
我在做
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor(){
super();
this.state = {
count: '0',
}
this.incrementCount = this.incrementCount.bind(this);
}
incrementCount() {
this.setState({
count: this.state.count + 1
});
}
render() {
return (
<div className='app'>
<div className='container'>
<button onClick={this.incrementCount}>Click to increase bid:
{this.state.count}</button>
</div>
</div>
);
}
}
export default App;
并收到错误
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
driver = webdriver.Chrome()
driver.get('https://www.carecredit.com/doctor-locator/')
driver.find_element_by_xpath("//select[@id='dl-
profession']/option[@value='9']").click()
driver.find_element_by_xpath("//*[@id='specialty-106']").click()
答案 0 :(得分:0)
回溯包含对错误的非常明确的解释。
WebDriverException:消息:未知错误:元素是 点击时不可点击(281,554)。其他元素会收到 点击:
您可能需要在两次单击之间添加延迟,以等待DOM更新以便元素可单击。
答案 1 :(得分:0)
以下是您的问题的答案:
此代码块将打开网址https://www.carecredit.com/doctor-locator
,点击Profession
下拉菜单,选择Weight Loss
,然后选中Weight Loss Surgery
复选框。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path= r"C:\\Utility\\BrowserDrivers\\chromedriver.exe")
driver.get('https://www.carecredit.com/doctor-locator/')
select = Select(driver.find_element_by_id('dl-profession'))
select.select_by_value("9")
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='specialty-106']//following::label[1]")))
driver.find_element_by_xpath("//input[@id='specialty-106']//following::label[1]").click()
如果这回答你的问题,请告诉我。