[英]Unable to click element by id , python selenium
嗨,我正在尝试查找和单击元素,但是它不起作用。 HTML代码如下
<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()
但它不起作用。 请帮助
尝试下面的代码,让它看看是否可行-
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")
我不了解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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.