2017-08-11 86 views
1

我試圖使用Selenium自動化一個過程。我幾乎總是使用:在Selenium中查找dymanic元素:「元素不可見」錯誤

driver.find_element_by_xpath('xpath') 

找到需要的元素。當我經歷的過程,我最終點擊打開一個對話框,這樣的元素:

http://imgur.com/a/NUoIM

元素我試圖點擊看起來像這樣:

http://imgur.com/1Zle5zG

問題是xpath和id都是動態的,所以每次創建一個新的會話時,我都會處理稍微不同的信息。

我所在的元素通過以下:

driver.find_element_by_xpath('//div[contains(@id, "56$187009")]/div[contains(@class, "gwt")]') 

但是當我嘗試和send_keys的元素,我收到以下錯誤:

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

我可以看到的元素屏幕,但似乎司機無法找到它。我試圖用:

driver.switch_to_alert() 

回答

1

試試下面的代碼行:

driver.find_element_by_xpath("//div[starts-with(@id, '56')][@class='WN5Q WCAR WCU']/input[contains(@class, 'gwt-TextBox WO5Q WBAR')]") 
+1

你是我在金甲夜。非常感謝!! –

+0

@JoeyB很高興能夠幫助你。 – DebanjanB