2017-09-06 167 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