2016-02-20 36 views
-1

我想開發一個簡單的機器人,喜歡從一個特殊的hashtag instagram照片。我正在使用硒,但我在「點擊圖片」的操作方面遇到了問題。登錄和搜索hashtag的作品。 xpath是正確的,但是當我運行該程序時,它沒有找到它。Selenium WebDriver機器人爲Instagram

public void like() { 
     driver.findElement(By.xpath(".//*[@id='react-root']/section/main/article/div[2]/div[1]/div[2]/a[1]/div[2]")) 
       .click(); 

    } 
+0

你試試你從Instagram的模擬數據的程序只是爲了排除它不是一個API的問題? – Michael

+0

我沒有使用API​​,因爲我沒有那個atm的知識。 – 100hp4ever

回答

0

點擊功能後:

for (int second = 0;; second++) { 
if (second >= 60) fail("timeout"); 
try { if (isElementPresent((By.xpath(".//*[@id='react-root']/section/main/article/div[2]/div[1]/div[2]/a[1]/div[2]")))) break; } catch (Exception e) {} 
     Thread.sleep(1000); 
    } 
相關問題