2017-12-20 12 views
2

これはウェブページですLINK私は(ペルシア語で)クロールするつもりです。私は次のページボタンをクリックするときに問題があります。Python Seleniumメッセージ:要素が表示されない

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 

いくつかの答えが重複したXPathのかもしれませんが、私は、ウェブページのソースにそのようなことを見つけることができなかったと言う:XPathは、私は次のエラーを得たpage.click()

nextpage = '//*[@id="ctl00_ContentPlaceHolder1_ASPxSplitter1_CallbackPaneldgd_dgd_DXPagerBottom"]/a[1]/img' 
page = driver.find_element_by_xpath(nextpage) 
page.click() 

です。

完全なコード:

import selenium 
from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
import time 
from selenium import webdriver 
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.webdriver.common.keys import Keys 
from selenium.webdriver import ActionChains 
driver = webdriver.Chrome(executable_path='./chromedriver') 
url = 'http://hmi.mrud.ir/sabaa/SABAA/Home/Default.aspx?strTownship=0101&g=false' 
driver.get(url) 
time.sleep(10) 
nextpage = '//*[@id="ctl00_ContentPlaceHolder1_ASPxSplitter1_CallbackPaneldgd_dgd_DXPagerBottom"]/a[1]/img' 
page = driver.find_element_by_xpath(nextpage) 
page.click() 

感謝。

答えて

1

は、要素をクリックする前に、次を使用します。

driver.execute_script("arguments[0].scrollIntoView(true);", page) 

これは、要素にスクロールされます。

希望すると助かります!あなたはをクリックしますWebsiteあたりとして

1

Next Page Button次のようにコードブロックのいずれかで、次のクリック可能であることをWebElementためWebDriverWaitを誘導する必要があります。

nextpage = WebDriverWait(driver, 10).until(EC.element_to_be_clickable(By.XPATH,"//div[@id='ctl00_ContentPlaceHolder1_ASPxSplitter1_CallbackPaneldgd_dgd_DXPagerBottom']/a[@class='dxp-lead dxp-button dxp-bi']/img[@class='dxWeb_pPrev_Aqua']")) 
nextpage.click() 

それとも

nextpage = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath("//div[@id='ctl00_ContentPlaceHolder1_ASPxSplitter1_CallbackPaneldgd_dgd_DXPagerBottom']/a[@class='dxp-lead dxp-button dxp-bi']/img[@class='dxWeb_pPrev_Aqua']")) 
nextpage.click() 
関連する問題