Reputation: 1
This code works fine in Firefox browser, but failing in Chrome browser saying not able to find element. Below is the html src code, i need to locate header .Kindly let me know how to get there ?
JAVA code:
WebElement frame = base.getWebDriver().findElement(By.xpath("//iframe[@id='cwindow']"));
base.getWebDriver().switchTo().frame(frame);
Thread.sleep(5000);
WebDriver driver = gen.getWebDriver();
WebElement form = base.getWebDriver().findElement(By.xpath("//div[@class='form input']"));
HTML code:
<iframe id="cwindow" name="cwindow" src="https://incentivesqa.ford.com/Flip/?app_context=t2&lang=en&make=Ford&model=Mustang&year=2014&zipcode=48126&paCode=03050&leadsource=FDAF-Inventory&altleadsource=SI&env=getlocaloffers&pageName=fv: si: vls: ford mustang&plan_type=MSRP">
<!DOCTYPE html>
<html>
<head>
<body>
<script src="/Scripts/Ford.Omniture.Control.js" type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<div class="header">
<div class="clear"></div>
<div class="incentive">
<script type="text/javascript">
<div class="flipFilter">
<select style="display : none;" name="modelDescription">
<div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="lcol" style="">
<div class="rcol">
<script type="text/javascript">
<div class="form thankYou">
<div class="form working">
<div class="form input">
<h2>Fill out the form below to receive special offers</h2>
<p class="error">
<table cellspacing="0" cellpadding="0" border="0">
<input id="address" type="hidden" value="" name="address">
</div>
<div class="aprLinkContainer">
</div>
<div class="clear"></div>
<div id="printContainer" style="display:none;">
<script type="text/javascript">
<script type="text/javascript">
</div>
<div id="omnitureTarget"></div>
<div id="dartTarget">
<div id="efficientFrontierTarget"></div>
</body>
</html>
</iframe>
Upvotes: 0
Views: 1773
Reputation: 108
You are probably facing the issue in chrome where you cant switch to frame
https://code.google.com/p/chromedriver/issues/detail?id=107
work around is here
https://code.google.com/p/chromedriver/issues/detail?id=107#c11
Upvotes: 0
Reputation: 29082
driver.switchTo().frame()
has the ability to select the frame | iframe based on the id
or name
attribute. Assuming you aren't using it down the road, make it easy on yourself and just do,
base.getWebDriver().switchTo().frame("cwindow");
Also, you should consider learning CSS. (By.cssSelector()
)
iframe#cwindow
is much prettier than
//iframe[@id='cwindow']
(much faster too)
As far as the cross-browser issue, it's possible that what @joostschouten said is accurate, about the <head>
tag not ending, and chrome might be complaining about that.
Upvotes: 1
Reputation: 3893
Your HTML is invalid. Amongst others, your <head>
may not be unclosed or empty. The fact that some browsers render it and allow you to find elements though their webdriver is because they are leniant and try to guess what you mean with your HTML. I also see a lot of empty <script>
tags and unclosed <div>
tags leaving me to believe you have not posted the exact HTML code.
Validate your HTML though the W3C Markup Validator. Once valid, try again and your code should give you your match. Though it won't find your header while using the xpath //div[@class='form input']
as that to me seems to be an xpath to form input in stead.
Upvotes: 0