我需要使用Selenium将光标放在textarea元素中。该元素没有ID。 我试过了:
def get_data(batchsize=None):
conn = psycopg2.connect('database parameter')
cursor = conn.cursor()
query = 'select * from table'
cursor.execute(query)
if not batchsize:
result = cursor.fetchall()
return result
else:
while True:
result = cursor.fetchmany(batchsize)
if not result:
break
yield result
if __name__ == '__main__':
data = get_data()
并抛出NoSuchElementException
答案 0 :(得分:4)
textarea
没有@class
- 它是祖先div
的属性。请尝试以下代码:
eventDriver.findElement(By.cssSelector("div.CodeMirror textarea")).click();
或使用ExplicitWait:
WebDriverWait wait = new WebDriverWait(eventDriver,10);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.CodeMirror textarea"))).click();
更新
WebElement element = eventDriver.findElement(By.cssSelector("div.CodeMirror textarea"))
JavascriptExecutor jse = ((JavascriptExecutor)eventDriver);
jse.executeScript("arguments[0].click()", element);