Reputation: 547
I've been searching for a solution to this problem for a good many days now, but have not been having much luck.
The versions I am using are as follows:
-Java 8
-Selenium 3.4.0
-PhantomJS 1.9.8 (Have had the same results with PhantomJS 2.1.1)
-JUnit 4.12 (The code is getting called through JUnit.)
Everything is happening on Windows 10 for this run, but I have had similar issues on CentOS 7.
I am attempting to run Selenium with PhantomJS and am running into issues getting a page to become fully available.
Below is a code snippet (with a ton of System.outs for testing purposes) in which I run into problems:
methodDriver.manage().window().maximize(); System.out.println(methodDriver.getPageSource()); WebElement trackingInbox = methodDriver.findElement(By.id("inbox-widget-container-id")); WebElement inboxBody = trackingInbox.findElement(By.xpath("div[1]/div[2]/table/tbody")); > List<WebElement> rows = inboxBody.findElements(By.tagName("tr"));
I get
"errorMessage":"Unable to find element with id 'inbox-widget-container-id'" at the line: WebElement trackingInbox = methodDriver.findElement(By.id("inbox-widget-container-id"));
This makes some since because when I print the page source at the second line, these are the DOM contents:
<body id="inboxBody" style="border:none; width:99%; align:center">
<div id="inboxContent">
<div class="mui-panel mui-panel-header">
<p class="mui--text-subhead">Tracking Inbox</p>
</div>
<div id="inboxes_div">
<div id="inboxes_control_section">
<div id="inboxes_control_inboxGroup" style="float: left; padding-right: 10px;padding-left: 5px;">
<select id="inbox_group" name="inbox_group"></select>
</div>
<div id="inboxes_control_inbox" style="float: left; padding-right: 10px;">
<select id="inboxes" name="inboxes"></select>
</div>
</div>
<p></p>
<div id="inbox_content_div" style="padding-top: 5px;"></div>
</div>
<input type="hidden" id="inbox_content_totalRecords" value="">
</div>
<br>
</body>
If, however, I use either chrome or firefox (headed) I get the following:
<body id="inboxBody" style="border: none; width: 957px;"><div id="inbox-widget-container-id" class="ui-resizable" style="width: 958px; margin-left: 1px; height: 500px;"><div class="grid-widget" style="width: 955px;"><div class="heading" style="background: linear-gradient(rgb(66, 139, 202), rgb(7, 105, 173)); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom: 0px; width: 955px;"><table class="heading" style="width: 938px; table-layout: fixed;"><tbody><tr><td style="text-align: center; height: 35px; width: 90px;"><div class="btn-group no-border condensed"><span class="btn btn-primary btn-sm thin-padding no-border hover-effect sortable" data-sortable-event="click">Case�#�<i class="fa fa-sort-amount-asc fa-fw fa-opaque"> . . .
<div id="inboxContent" style="display: none;">
<div class="mui-panel mui-panel-header">
<p class="mui--text-subhead">Tracking Inbox</p>
</div>
<div id="inboxes_div">
<div id="inboxes_control_section">
<div id="inboxes_control_inboxGroup" style="float: left; padding-right: 10px;padding-left: 5px;">
<select id="inbox_group" name="inbox_group"><option value="inbox.group.case">Case</option><option value="group.InvestiagtionItems">Investigation Items</option></select>
</div>
<div id="inboxes_control_inbox" style="float: left; padding-right: 10px;">
<select id="inboxes" name="inboxes"><option value="inbox.cases">Assigned</option></select>
</div>
</div>
<p></p>
<div id="inbox_content_div" style="padding-top: 5px;"></div>
</div>
<input type="hidden" id="inbox_content_totalRecords" value="" />
</div>
<br />
</body>
Notice that the first line goes on for a very long time (I deliberately cut it short here). That line contains the elements I want to work with, but are not showing up in PhantomJS.
Above the “” element, there is a large “” element with a jquery script. I have heard suggestions that this script is not running in phantomjs and that it would populate the DOM if it did. So, maybe I need to find out how to get it to run in phantom, though I am having some trouble figuring out how to do that.
Upvotes: 1
Views: 68
Reputation: 5127
It looks like you need to wait for an element. Otherwise, the website doesn’t allow PhantomJS. Let’s try the wait first, see the example below.
WebDriverWait wait = new WebDriverWait(methodDriver, 10);
WebElement trackingInbox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("inbox-widget-container-id")));
Upvotes: 1