I'm trying to automate a click in iframe. I've removed all the un-necessary code piece and sharing the minimal code which causes the issue. Here is the extracted code,
a.html -> points to b.html in iframe
<html>
<head></head>
<body>
<IFRAME width="100%" height="100%" id="iframe" src="b.html" style="HEIGHT: 100% !important; WIDTH: 100% !important">
</IFRAME>
</body>
</html>
b.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
DIV {
vertical-align: top;
font-family: Verdana;
font-size: 10px;
}
#left_container_menu {
position: absolute;
overflow-x: hidden;
overflow-y: scroll;
left: 9px;
width: 190px;
top: 30px;
bottom: -3px;
}
BODY {
vertical-align: top;
font-family: Verdana;
font-size: 10px;
}
BODY {
background-color: #ffffff;
}
BODY {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: auto;
}
HTML {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: auto;
}
.menu_content_in {
border-left: solid #D1D1D1 1px;
border-right: solid #D1D1D1 1px;
border-bottom: solid #D1D1D1 1px;
padding: 2px 0px 4px 2px;
}
A {
text-decoration: none;
color: black;
line-height: 14px;
margin: 3px;
}
</style>
</head>
<BODY>
<DIV id=left_container_menu>
<DIV id=ctl00_Menu_ctl02_Submenu_header_CollapsablePanelUpdatePanel>
<DIV class=menu_content_in>
<A tabIndex=-1 href="e.html">test1</A><BR>
<A tabIndex=-1 href="d.html">test2</A><BR>
<A tabIndex=-1 href="c.html">test3</A><BR></DIV></DIV>
</DIV>
</BODY>
</html>
Now, when I try to click the element using following c# code via selenium web driver, the test3
link is not clicked. It doesn't give me any error/warning. It silently goes through the click method. Code is as follows,
d.SwitchTo().Frame("iframe");
IWebElement e = d.FindElement(By.XPath("//*[@id='ctl00_Menu_ctl02_Submenu_header_CollapsablePanelUpdatePanel']/div/a[3]"));
e.Click();
d.SwitchTo().DefaultContent();
Why is the link test3
not clicked?
The interesting fact is when, I remove following CSS code, I'm able to automate the click.
#left_container_menu {
position: absolute;
overflow-x: hidden;
overflow-y: scroll;
left: 9px;
width: 190px;
top: 30px;
bottom: -3px;
}
What is so special about this CSS? I want to make the element clickable. How do I do that?
Note : I can't change the html source code, due to legacy reasons. But I change anything via c# to make the click happen. Any pointers is greatly appreciated.
My package list,
I can't automate the click on Chrome/Firefox, as the website works only on IE. I'm attaching my IE version as well.
Here is the code that I am using on my side. I have just added your code to my test code.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
namespace selenium_IE_automation
{
class Program
{
private const string IE_DRIVER_PATH = @"D:\D drive backup\selenium web drivers\";
static void Main(string[] args)
{
string url = "http://localhost/a.html";
var driver = new InternetExplorerDriver(IE_DRIVER_PATH);
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
try
{
driver.SwitchTo().Frame("iframe");
IWebElement leverancierlinkElement = driver.FindElement(By.XPath("//*[@id='ctl00_Menu_ctl02_Submenu_header_CollapsablePanelUpdatePanel']/div/a[3]"));
leverancierlinkElement.Click();
driver.SwitchTo().DefaultContent();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Output:
Edit:
IE driver server version:
Selenium web driver version:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.