Python Selenium::元素当前不可见
所以我正在访问这个链接,在朋友的帮助下,我可以进步一点。现在我被卡住了。问题是,当有人单击Python Selenium::元素当前不可见,python,selenium,Python,Selenium,所以我正在访问这个链接,在朋友的帮助下,我可以进步一点。现在我被卡住了。问题是,当有人单击Reply并单击Post按钮时,表示元素当前不可见,因此可能无法与之交互 代码如下: import requests from bs4 import BeautifulSoup from gensim.summarization import summarize from selenium import webdriver from datetime import datetime from seleni
Reply
并单击Post
按钮时,表示元素当前不可见,因此可能无法与之交互
代码如下:
import requests
from bs4 import BeautifulSoup
from gensim.summarization import summarize
from selenium import webdriver
from datetime import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from time import sleep
import sys
import os
import xmltodict
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import traceback
import random
driver = None
driver = webdriver.Firefox()
driver.maximize_window()
url = 'https://steemit.com/steem/@ozchartart/usdsteem-btc-technical-analysis-2-the-only-way-for-me-to-move-on-is-to-chart-it-in-the-dawn'
driver.get(url)
sleep(5)
f = driver.find_element_by_css_selector('.PostFull__reply')
location = f.location["y"] - 100
driver.execute_script("window.scrollTo(0, %d);" % location)
f.click()
t = driver.find_element_by_tag_name('textarea')
b = driver.find_element_by_tag_name('button')
# b = WebDriverWait(driver, 20).until(
# EC.presence_of_element_located((By.TAG_NAME, "button"))
# )
# print(b)
t.click()
sleep(1)
t.send_keys('awesome!!')
sleep(2)
driver.execute_script("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1",b)
driver.execute_script('document.getElementsByTagName("button")[0].click();')
#if b.is_displayed():
b.click()
except Exception as e:
driver.save_screenshot('myscreen.png')
print(str(e))
好像你想用另一个按钮来交互。请尝试更具体的选择器:
driver.find_element_by_xpath('//button[text()="Post"]').click()
这对我来说很有用我找到了这个@grooveplex,如果你看到的话,我已经用过了,但是没有用。你试过悬停并单击吗?