2017-09-06 58 views
0

嗨我試圖找到並單擊該元素,但它不工作。 HTML代碼的下面無法通過ID點擊元素,python selenium

<a href="#" class="button blue block" id="tollstation">Toll Plaza(s) Between Two Stations </a>

我想如下

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'tollstation')))

等一個

element = driver.find_element_by_id('tollstation') element.click()

,但它不工作。 PLZ幫助..

+0

是tollstation id是唯一的嗎? ..有任何幀出現在DOM –

+0

您確定該頁面正在加載? – dhdavvie

+0

是正在加載頁面, 這裏是我的代碼 'path_to_chromedriver = 'C:/用戶/黃芪多糖/桌面/ WebScrap /硒/ chromedriver' 瀏覽器= webdriver.Chrome(executable_path = path_to_chromedriver) URL =「HTTP ://tis.nhai.gov.in/tollplazasonmap語言= EN ' browser.get(URL) 元素= driver.find_element_by_id( 'tollstation') element.click() 在element2 = driver.find_element_by_class_name(' 按鈕綠色 ') driver.find_element_by_id(' txtfrom ')。send_keys( 「德里」) driver.find_element_by_id(' txtto')。send_keys( 「班加羅爾」) element2.click() driver.implicitly_wait(1 0)' – Prashant

回答

-1

我沒有python的知識,所以我在java中編碼,請將它轉換爲python

System.setProperty("webdriver.chrome.driver", "E:\\software and tools\\chromedriver_win32\\chromedriver.exe"); 
WebDriver driver = new ChromeDriver(); 
driver.get("http://tis.nhai.gov.in/tollplazasonmap?language=en"); 
driver.manage().window().maximize(); 
WebElement frame1=driver.findElement(By.xpath("//embed[@src='map1.htm']")); 
driver.switchTo().frame(frame1); 
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
WebElement tollstation= driver.findElement(By.id("tollstation")); 
JavascriptExecutor js=(JavascriptExecutor)driver; 
js.executeScript("arguments[0].click()",tollstation); 
0

與嘗試下面的代碼,並讓我們看看它是否工程─

driver.get(url) 
embed = driver.find_element_by_tag_name('embed') 
driver.switch_to.frame(embed) 
element = driver.find_element_by_id('tollstation') 
driver.execute_script("arguments[0].click();", element) 

答案在評論 -

問題

相反的 - 下面的代碼

element2 = driver.find_element_by_class_name('button green') 

使用 -

element2 = driver.find_element_by_xpath("//*[@id='showstation']/p[7]/a") 
+0

非常感謝..它的工作。 – Prashant

+0

但畢竟這當我填充數據 '在element2 = driver.find_element_by_class_name( '按鈕綠色') driver.find_element_by_id( 'txtfrom')。send_keys( 「德里」) driver.find_element_by_id( 'txtto')。 send_keys(「Bangalore」) element2.click()' 再次沒有發生...... – Prashant

+0

老兄,像'不發生'/'不工作'這樣的詞不會幫助你。你需要告訴我們DOM和你得到的錯誤。 – Kapil