2016-07-30 72 views
1

所以我訪問this鏈接和this朋友的幫助,我能夠進步一點。現在我被卡住了。問題是,當有人點擊Reply並單擊Post按鈕,它說:Element is not currently visible and so may not be interacted withPython Selenium ::元素是目前隱形

守則如下:

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)) 
+0

,我發現這個https://selenium-python.readthedocs.io/waits.html#explicit-waits – grooveplex

+0

@grooveplex如果你看到,我已經使用它,但沒有工作 – Volatil3

+0

你試圖懸停和點擊? – lloyd

回答

1

看來,你試圖用另一個按鈕interract。嘗試更具體的選擇:

driver.find_element_by_xpath('//button[text()="Post"]').click() 

這對我的作品