Unable to click or select checkbox using selenium python webdriver chrome - python-3.x

After all unsuccessful tries I had to ask for the help.
The thing is I want to make script which will automatically login, go to specific tab ("WAN"), click appropriate check box (to disable NAT) and log out. (It's actually Huawei GPON router HG8245)..
My code goes fine until the check box, so...
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
driver=webdriver.Chrome(r"C:\chromedriver.exe") #load the driver => OK
driver.get("http://192.168.100.1") #go to this web page => OK
driver.find_element_by_id("txt_Username").send_keys("root") #username=root => OK
driver.find_element_by_id("txt_Password").send_keys("root") #password=root => OK
driver.find_element_by_xpath(".//*[#id='button']").click() #click Submit button => OK
driver.find_element_by_xpath(".//*[#id='headerTab']/ul/li[2]/div[2]").click() #Go to the 'WAN' tab => OK
And for the clicking of check box my tries:
#1
driver.find_element_by_xpath("//input[#value='InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1']").click() #=> NOT OK
#2
driver.find_element_by_xpath("//*[#id='record_1']/td[1]/input").click() #=> NOT OK
#3
driver.find_element_by_css_selector("#record_1 > td > input[name=\"rml\"]").click() #=> NOT OK
Of course all xpaths are checked in chrome via console (in the Mozilla as well) and they seems fine!
Any ideas how to solve this?
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>[![enter image description here][1]][1]
<div id="main">
<div id="header">
<div id="center" style="height: 495px;">
<div id="nav" style="height: 495px;">
<div id="content" style="height: 495px;">
<div id="topNav">
<div id="frameWarpContent" style="height: 470px;">
<iframe id="frameContent" marginheight="0" marginwidth="0" scrolling="no" src="html/network/wan.asp" style="height: 470px;" height="100%" frameborder="0" width="100%">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="Page" xmlns="http://www.w3.org/1999/xhtml" dir="ltl">
<head>
<body class="mainbody">
<script language="JavaScript" src="../../resource/common/util.js?1103405">
<script language="JavaScript" src="../../resource/english/jsdiff.js?1103405">
<script language="JavaScript" src="../../resource/common/tabdes.js?1103405">
<script language="javascript" src="../common/manage_mode.asp">
<script language="javascript" src="../common/user_info.asp">
<script language="javascript" src="../common/topo_info.asp">
<script language="javascript" src="../common/feature_info.asp">
<script language="javascript" src="../common/wan_prefix_acquire.asp">
<script language="javascript" src="../common/wan_address_acquire.asp">
<script language="javascript" src="../common/wan_dns.asp">
<script language="javascript" src="../common/wan_list.asp">
<script language="javascript" src="../common/wlan_list.asp">
<script language="javascript" src="../common/lanmode_list.asp">
<script language="javascript" src="../common/policyroute_list.asp">
<script language="javascript" src="wan_language.html?1103405">
<script language="javascript" src="../common/wan_pageparse.html?1103405">
<script language="javascript" src="../common/wan_databind.html?1103405">
<script language="javascript" src="../common/wan_control.html?1103405">
<script language="javascript" src="../common/wan_check.html?1103405">
<script language="JavaScript" src="../../resource/english/bbspdes.html?1103405">
<script>
<div id="PromptPanel">
<script>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td id="Wan Connection">
<table id="wanInstTable" class="tabal_bg" width="100%" cellspacing="1">
<tbody>
<tr class="tabal_title">
<tr id="record_0" class="tabal_01" onclick="selectLine(this.id);">
<tr id="record_1" class="tabal_01" onclick="selectLine(this.id);">
<td align="center">
<input name="rml" value="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1" onclick="" type="checkbox">
</td>
<td align="center">
<td align="center">
<td title="RealName :HSI Status :Connected IPAddress :10.10.10.10" align="center">
</tr>
</tbody>
</table>
<script>
<form id="ConfigForm">
</td>
</tr>
</tbody>
</table>
</body>
</html>
</iframe>
</div>
</div>
</div>
<div id="footer">
<div id="fresh">
</div>
</body>
</html>
*Edit: Modifying code tags and IP values

Considering provided HTML code sample you need to switch to iframe before handling check-box:
driver.switch_to.frame("frameContent")
driver.find_element_by_xpath("//tr[#id='record_1']//input").click()

Related

Bad color in table. Bootstrap 5.2.3

I have no practice as a bootstrap user.
I have a table. when i set dark mode in browser then the color of text is wrong (black on black background).
What am I doing wrong?
(fg-color is only bad in table when class="table" added)
<!doctype html>
<html lang="pl">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/nav_sidebar.css">
<link rel="stylesheet" type="text/css" href="/static/admin/css/dashboard.css">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="/static/admin/css/responsive.css">
</head>
<body>
<table class="table table-responsive table-bordered">
<thead>
<tr>
<th class="text-center" scope="col">Name</th>
<th class="text-center" scope="col">Price</th>
<th class="text-center" scope="col">Qnt</th>
</tr>
</thead>
<tbody>
<tr>
<td>product 1</td>
<td class="text-end">12,48</td>
<td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
</tr>
<tr>
<td>product 2</td>
<td class="text-end">12,48</td>
<td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
</tr>
<tr>
<td>product 3</td>
<td class="text-end">12,48</td>
<td class="float-right"><input class="form-control float-right" type="number" min="1" max="999"></td>
</tr>
</tbody>
</table>
</body>
</html>
I tried using a div container and some classes but it doesn't change anything.
For styling depending on browser based color mode/theme, you can use the prefers-color-scheme media query as it is used to detect whether the user has requested a light or dark theme based on operating system setting or user agent (browser in this case) settings.
You can set the color for the table using this query:
#media (prefers-color-scheme: dark) {
your-selector {
color: white;
}
}
Reference - MDN

VBA Excel - Filling in webforms unable to click submit button

I am fairly new to coding and took on this project to create 1000 new accounts in an internal program we have at my work. I was able to get the macro to fill in the webform and proceed through 2 pages however at the third page I was unable to get it to click the submit button.
Code:
Sub Automate1()
Dim IE As Object
Dim doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://associate.heritagerep.com/signup/signup.asp?
SectionID=10&t=10030&guid=CB57C450-F8D2-4644-98CB-99C37DA43668"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
'First Screen'
doc.getElementsByName("sponsor")(0).Value = "kffrep"
doc.getElementById("Username").Value = "75871"
doc.getElementById("email").Value = "75871#kff.com"
doc.getElementById("zip").Value = "111111"
doc.getElementsByName("Submit")(0).Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Second Screen'
doc.getElementById("companyName").Value = "kff1"
doc.getElementById("OccupationTy_Select").Value = 34
doc.getElementById("fname").Value = "75871"
doc.getElementById("lname").Value = "kff1"
doc.getElementById("mstreet1").Value = "1 kff st"
doc.getElementById("mcity").Value = "Mississauga"
doc.getElementById("mstate").Value = "ON"
doc.getElementById("hphone").Value = "1111111"
doc.getElementById("emailConfirm").Value = "75871#kff.com"
doc.getElementsByName("SSN")(0).Value = "000000000"
doc.getElementById("password").Value = "password1"
doc.getElementById("passwordconfirm").Value = "password1"
doc.getElementsByName("securityanswer")(0).Value = "pizza"
doc.getElementsByClassName("btn btn-primary")(0).Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Third Screen'
Set tags = doc.getElementsByClassName("btn btn-success")
For Each tagx In tags
If tagx.Name = "submitfinish" Then
tagx.Click
End If
Next
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Fourth Screen'
doc.getElementsByName("Submit3")(0).Click
'Fifth Screen'
doc.getElementsByName("CheckOrderPaid")(0).Click
doc.getElementsByName("Shipped")(0).Click'
doc.getElementsByName("subAdminOpt")(0).Click
Flag
End Sub
Below is the HTML code for the troublesome button:
<input name="submitfinish" class="btn btn-success" type="submit" value="Finish Order">
I am not sure why the actions I used in the first 2 pages to click the submit button are suddenly not working on the third page. I have tried may different iterations trying to work around the problem but have yet to find one that is successful.
Appreciate any feedback.
Additional DOM Details:
<div class="text-right">
<a class="btn btn-default" href="/default.asp?guid=651F5B01-725B-4CCD-B12E-17CD5D59C472">Continue Shopping<!--Continue Shopping--></a>
<input name="submitcalc" class="btn btn-default" type="submit" value="Re-Calculate">
<input name="submitfinish" class="btn btn-success" type="submit" value="Finish Order"><!--Finish Order -->
</div>
Entire webpage HTML:
<!DOCTYPE html>
<html lang="en" class="non-mobile">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<meta content='width=device-width, initial-scale=1.0, maximum-
scale=1.0, user-scalable=0' name='viewport' />
<!-- Scripts -->
<script type="text/javascript" src="//code.jquery.com/jquery-
1.11.0.min.js"></script>
<script type="text/javascript" src="/common/script.js"></script>
<script type="text/javascript" src="/common/function/script_source.js"></script>
<script type="text/javascript" src="/common/jquery/jquery.validate.min.js"></script>
<script type="text/javascript" src="/common/function/functions.js"></script>
<!-- bootstrap -->
<script type="text/javascript" src="/responsive/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/responsive/js/common.js"></script>
<script type="text/javascript" src="/common/shadowbox/shadowbox.js"></script>
<script type="text/javascript" src="/responsive/js/jquery.animate-colors-min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.js"></script>
<script type="text/javascript" src="//unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- CSS -->
<link href="/common/shadowbox/shadowbox.css" rel="stylesheet">
<link href="/responsive/css/bootstrap.css" rel="stylesheet">
<link href="/responsive/css/bootstrap-custom.css" rel="stylesheet">
<link href="/responsive/css/bootstrap-ms.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" rel="stylesheet">
<!-- Parent Site overrides -->
<link href="//associate.heritagerep.com/clientinc/resources/css/common.css" rel="stylesheet">
<style type="text/css">
#import url('//associate.heritagerep.com/common/templates/public/css/custom.css');
</style>
<script type="text/javascript">
$(function() {
app.init({ domain: 'associate.heritagerep.com'});
});
</script>
</head>
<body class="responsive">
<!-- This is a helper so javascript can see whether or not this is a mobile device -->
<div id="isMobile" class="visible-xs"></div>
<form method="post" name="currencyty">
<input type="hidden" name="CartId" value="439915">
<table class="table table-striped">
<thead>
<tr>
<th>ItemCode<!--ItemCode--></th>
<th>Description<!--Descr--></th>
<th>Qty<!--Qty--></th>
<th>Currency<!--Currency--></th>
<th>Price Each<!--Price Each--></th>
<th>
Volume
</th>
<th>Volume 2<!--Volume 2--></th>
<th>Price Total<!-- Total--></th>
<th>
Points Total
</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td> <!-- ITEM CODE -->
1004
</td>
<td><!-- Description -->
Initial Certification Fee
</td>
<td> <!-- QTY -->
<input name="Qty_609000021&609000020&0&-1&1004&N" type="text" value="1" size="2" onblur="WidthTest(this,1);" />
</td>
<td>CAD</td>
<td>
$25.00
</td>
<td>
0
</td>
<td>
0
</td>
<td>
$25.00
</td>
<td>
0
</td>
<td class="text-right">
Edit<!--Edit-->
</td>
</tr>
<tr>
<td colspan="100%">
<div class="pull-left">
Add Item<!--Add-->
</div>
<div class="pull-right">
<input name="adItemCode" type="text" value="Item Code" size="10" onclick="this.value = ''" onblur="WidthTest(this,1);AddTableRow('ProductItemCode')"><!--Item Code-->
Qty:<!--Qty:--> <input name="adNewQty" type="text" value="1" size="2" onblur="WidthTest(this,1);">
<span style="font-weight:bold;vertical-align: middle; float: right;">
<input type="submit" name="submitadd" value="Add Item" onclick="whichButton='add';"><!--Add Item-->
</span>
</div>
</td>
</tr>
</tbody>
</table>
<div class="pull-right">
<ul class="list-group">
<li class="list-group-item">
<strong>Volume:</strong>
0
</li>
<li class="list-group-item">
<strong>Totals<!--Totals :-->:</strong>
$25.00
</li>
</ul>
</div>
<div class="clearfix"></div>
<div class="text-right">
Continue Shopping<!--Continue Shopping-->
<input type="submit" name="submitcalc" value="Re-Calculate" class="btn btn-default">
<input type="submit" name="submitfinish" value="Finish Order" class="btn btn-success"><!--Finish Order -->
</div>
</form>
<script language="javascript">
$(function() {
$('.fancy').fancybox({
'width' : '75%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'topRatio': '0.1',
'autoHeight': true
});
});
</script>
</body>
You could try and attribute = value selector to target element. Let us know if an error and if so check if there is a parent iframe/frame tag.
ie.document.querySelector("[value='Finish Order']").click
Or
ie.document.querySelector("[value='Finish Order']").FireEvent "onclick"

Bootstrap Modal Windows in NodeJS

I am developing a dashboard website in NodeJS and MongoDB. In one of the page, I have to open an image in the modal window. Following is the code of that page.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tor Modal Check</title>
<link rel="stylesheet" href="css/style.default.css" type="text/css" />
<link rel="stylesheet" href="css/responsive-tables.css">
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery-migrate-1.1.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script type="text/javascript" src="js/jquery-ui-1.9.2.min.js"></script>
<script type="text/javascript" src="js/modernizr.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.bxSlider.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery.uniform.min.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="js/flot/jquery.flot.min.js"></script>
<script type="text/javascript" src="js/jquery.slimscroll.js"></script>
<script type="text/javascript" src="js/flot/jquery.flot.pie.min.js"></script>
<script type="text/javascript" src="js/flot/jquery.flot.resize.min.js"></script>
<script type="text/javascript" src="js/responsive-tables.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
<style type="text/css">
body .modal {
width: 650px;
margin-left: -325px;
}
</style>
</head>
<body>
<div class="mainwrapper">
<div class="rightpanel">
<ul class="commentlist">
<% tor.forEach(function(t){ %>
<li>
<img src="images/screenshot/<%= t.screenshot %>" alt="" style="width: 60px;" class="pull-left" />
<div class="comment-info">
<h4><%= t.url %></h4>
<p><strong>Comments: </strong><%= t.comments %></p>
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#<%= t.modalid %>">Show Screenshot</button>
<!-- Modal -->
<div class="modal fade" id="<%= t.modalid %>" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><%= t.url %></h4>
</div>
<div class="modal-body">
<img src="images/screenshot/<%= t.screenshot %>" height="100%" width="100%">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<% }) %>
</ul>
</div>
</div>
</body>
The problem that I am facing is that not all "View Screenshot" are clickable. After digging a lot, I figure it's because of "rightpanel" div class.
/*** MAIN PANEL ***/
.rightpanel { margin-left: 260px; background: #f7f7f7; }
.rightpanel:after { clear: both; content: ''; display: block; }
If I remove margin-left: 260px; everything works as expected.
Any idea why this is happening and how to overcome it?
PS. This is not the complete code. Only the code that is significant for this question.
EDIT 1:
It works perfectly fine when i change margin-left: 260px to margin-left: 150px.
Bootstrap modals are already centered and have three sizes (300px for .modal-sm, 600px (default) and 900px for .modal-lg). But, if you need the width to be exactly 650px, you should set the width of .modal-dialog, not .modal. For example:
#media (min-width: 768px)
.modal-dialog {
width: 650px;
}

How to pull a text from a table but the table has the same name as other tables? VBA, excel

I've made a code that would go to a website and pull their investment criteria. But I only need one cell in that table and the table class name is the same for multiple tables.
I need to get the EBITDA, which is on the table class = cTblListBody
Here's my code thus far:
Sub SearchBot()
Dim objIE As InternetExplorer
Dim aEle As HTMLLinkElement
Dim y As Integer
Dim result As String
Dim TR As Object, TD As Object
Dim tbl As Object, obj_tbl As Object
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://website.com"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.document.getElementById("SearchTopBar").Value = _
Sheets("Sheet2").Range("A2").Value
Set oNode = objIE.document.getElementsByClassName("iPadHack tmbsearchright")
(0)
oNode.Click
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
b = 2
Dim tblEle
Set tblEle = objIE.document.getElementsByClassName("cTblListBody")(5)
Sheets("Sheet2").Range("B" & b).Value = tblEle.innerText
Debug.Print tblEle.innerText
b = b + 1
Next
objIE.Quit 'close the browser
End Sub
Full html code:
html
<head id="ctl02_headcontrol">
<body>
<div id="gcontainer" style="z-index:200000" onmouseout="calendarTimeout();"
onmouseover="if (timeoutId) clearTimeout(timeoutId);"></div>
<style>
<script type="text/javascript">
<img id="_jsVersionedShim" title=""
src="https://w3.ciqimg.com/CIQDOTNET/images/shim.gif?urwvid=3502569" alt=""
style="display:none;">
<script type="text/javascript">
<link title="IQ" rel="search"
type="application/opensearchdescription+xml"
href="/ciqdotnet/search/autocompleteprovidergenerator.axd">
<link rel="stylesheet" type="text/css"
href="/CIQDOTNET/library/Combined/CIQHeader.css">
<style>
<div id="topBanner" style="width: 100%; height: 69px;">
<table style="height: 100%" width="100%" cellspacing="0" cellpadding="0"
border="0">
<tbody>
<tr valign="bottom">
<tr id="bodyrow" style="height:100%;" valign="top">
<td id="ll_leftBorder_mid">
<td id="ll_cont" class="ll_cont_ex">
<td id="leftPageBorder" style="width: 10px;">
<td style="width: 100%;">
<div id="contentArea">
<script type="text/javascript">
<script type="text/javascript">
<div id="UpdateProgressDiv" style="visibility:hidden;"></div>
<script type="text/javascript"
src="/CIQDotNet/Charting/Library/highstock.js">
<script type="text/javascript"
src="/CIQDotNet/CreditAnalytics/CIQCharts/themes/light.js">
<script type="text/javascript"
src="/CIQDotNet/CreditAnalytics/CIQCharts/lib/util.js">
<script type="text/javascript"
src="/CIQDotNet/CreditAnalytics/CIQCharts/CIQCharts.js">
<style type="text/css">
<script type="text/javascript"
src="/CIQDotNet/News/library/NewsAndBlogs.js">
<script type="text/javascript">
<form id="frmMain" method="post" action="./company.aspx?companyId=30995038">
<div class="aspNetHidden">
<script type="text/javascript">
<script src="/CIQDotNet/WebResource.axd?d=nZzj3YZngGCPUXbcooPdPCjPJSuAIp
DU_l-5lPsFAlauINflCZuBPW8NfeQFL1nsY13w4LY1&t=635802961220000000"
type="text/javascript">
<script language="javascript">
<script src="/CIQDotNet/LeftLinks/LeftLinksContent.aspx
leftLinksHashKey=e1HX3w3nPsHpyHn6IEXdcA%3d%3d&urwvid=3502569"
type="text/javascript">
<script type="text/javascript">
<script src="/CIQDotNet/library/CIQDotNet/Web/functional.js"
type="text/javascript">
<script type="text/javascript">
<script src="/CIQDotNet/ScriptResource.axd
d=BQRO1XhoYSDCQiunG6j3W6BEdFJUaLhgrsqvXzeFZkJH6K5tgvKMDrgFuDHlO
1ymPMZRaduCK4dNstqE6toFrC4k8xUF9d5645" type="text/javascript">
<script src="/CIQDotNet/ScriptResource.axd?
<script src="Company/BubbleChart.asmx/js" type="text/javascript">
<script type="text/javascript">
<script src="/CIQDotNet/Research/Services/ResearchService.asmx/js"
type="text/javascript">
<div class="aspNetHidden">
<script type="text/javascript">
<div id="CompanyHeaderInfo" class="cPageTitle" style="margin-bottom:38px;">
<table class="cTblListBody" style="width:100%;" border="1">
<div style="width:100%;">
<div style="width:100%;">
<div style="width:100%;">
<div style="width:100%;">
<br class="tableSpacer">
<table style="width:100%;border-collapse:collapse;" cellspacing="0"
cellpadding="0">
<tbody>
<tr>
<td>
<table class="cTblHeaderBG" style="width:100%;">
<table class="cTblListBody" style="width:100%;border-collapse:collapse;"
cellspacing="0" cellpadding="2">
<a name="#ctl22$ctl09"></a>
<table class="cTblListBody" rules="all" cellspacing="1" cellpadding="2"
bordercolor="#d8dde1" border="1">
<tbody>
<tr class="cColHeaderBG">
<tr>
<tr style="background-color:#F9F9F9;">
<tr>
<tr style="background-color:#F9F9F9;">
<td>EBITDA</td>
<td style="width:50px;" align="right">
<span></span>
-
</td>
<td style="width:50px;" align="right">
<td style="width:50px;" align="right">
<td style="width:50px;" align="right">
</tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%;">
<div style="width:100%;">
<div style="width:100%;">
<div style="width:100%;">
<br class="tableSpacer">
<div> </div>
<script type="text/javascript">
<script type="text/javascript">
<script language="JavaScript">
<script language="JavaScript">
<script language="JavaScript">
<script type="text/javascript">
</form>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
</div>
</td>
<td id="rightPageBorder" style="width: 10px;">
</tr>
<tr valign="top">
</tbody>
</table>
<div id="btmFooter" class="ftrBG">
<a id="_hotkey1" accesskey="1" tabindex="-1" onclick="HotKey(1);"
onfocus="HotKeyIE(1)" href="javascript:void(0);"
style="position:fixed;top:0;left:0"></a>
<a id="_hotkey2" accesskey="2" tabindex="-1" onclick="HotKey(2);"
onfocus="HotKeyIE(2)" href="javascript:void(0);"
style="position:fixed;top:1;left:0"></a>
<a id="_hotkey3" accesskey="3" tabindex="-1" onclick="HotKey(3);"
onfocus="HotKeyIE(3)" href="javascript:void(0);"
style="position:fixed;top:2;left:0"></a>
<a id="_hotkey4" accesskey="4" tabindex="-1" onclick="HotKey(4);"
onfocus="HotKeyIE(4)" href="javascript:void(0);"\
style="position:fixed;top:3;left:0"></a>
<a id="_hotkey5" accesskey="5" tabindex="-1" onclick="HotKey(5);"
onfocus="HotKeyIE(5)" href="javascript:void(0);"
style="position:fixed;top:4;left:0"></a>
<a id="_hotkey6" accesskey="6" tabindex="-1" onclick="HotKey(6);"
onfocus="HotKeyIE(6)" href="javascript:void(0);"
style="position:fixed;top:5;left:0"></a>
<a id="_hotkey7" accesskey="7" tabindex="-1" onclick="HotKey(7);"
onfocus="HotKeyIE(7)" href="javascript:void(0);"
style="position:fixed;top:6;left:0"></a>
<a id="_hotkey8" accesskey="8" tabindex="-1" onclick="HotKey(8);"
onfocus="HotKeyIE(8)" href="javascript:void(0);"
style="position:fixed;top:7;left:0"></a>
<a id="_hotkey9" accesskey="9" tabindex="-1" onclick="HotKey(9);"
onfocus="HotKeyIE(9)" href="javascript:void(0);"
style="position:fixed;top:8;left:0"></a>
<a id="_hotkey0" accesskey="0" tabindex="-1" onclick="HotKey(0);"
onfocus="HotKeyIE(0)" href="javascript:void(0);"
style="position:fixed;top:9;left:0"></a>
</body>
</html>
You need to get the third instance of that ClassName, so, instead of looping the collection of matching ClassName elements, try this:
Dim tblEle
Set tblEle = objIE.document.getElementsByClassName("cTblListBody")(2)
Then, I think you can you get the cell value from that element.
Also note:
You use variable i but I don't see that declared anywhere in code: For Each aEle In objIE.document.getElementsByClassName("cTblListBody").Rows.
(i).Cells(1).innerText. Should this be b instead of i?

Watir-Webdriver Can't access a element with id and class

I am having a trouble trying to access a nested div that has id and class, I don't know why but I only can see his parent.
This is the HTML code:
<html xml: lang="en" xmlns="http://www.w3.org/1999/xhtml" webdriver="true">
<head id="ctl00_Head1"></head>
<body onunload="deshabilitaHistoria();" onload="deshabilitaHistoria();">
<form id="aspnetForm" action="ConsultaReceptor.aspx" method="post">
<div class="aspNetHidden"></div>
<script type="text/javascript">
//<![CDATA[ var theForm = document.forms['aspnetF…
</script>
<script type="text/javascript" src="/WebResource.axd?d=w3hP2KgSK0z5QKKeYrfjOjGIUO1WTymINPb1PJaT2…AjAREgWLQ_9gOp19BJLQL03iwEhxTK_VlYMMLk1&t=635757173565717094"></script>
<script type="text/javascript" src="/ScriptResource.axd?d=JZxa8gqDBBrScXZMeyf5kBYrESwOlB3UypK5wa…sdGfW92qpYAba8RsL1xfZ_4qsx20HZ3gnR8gWNG81&t=ffffffff805766b3"></script>
<script type="text/javascript" src="/ScriptResource.axd?d=Z6KcuJ_OzxT6nvHmSunXcYkoXPPYk2iZ6iqqza…Mhq8K8bd09EWTYt8d-AfoMh3rrp75DWb5vMAI1wb0&t=ffffffff805766b3"></script>
<script type="text/javascript">
//<![CDATA[ var PageMethods = function() { PageMe…
</script>
<div class="aspNetHidden"></div>
<script type="text/javascript">
//<![CDATA[ Sys.WebForms.PageRequestManager._init…
</script>
<div id="cuerpo_principal">
<div id="encabezado"></div>
<div id="menucontainer"></div>
<div id="cuerpo" style="margin-top: 30px">
<h2 class="subtitle">
Consultar Facturas Recibidas
</h2>
<span></span>
<br></br>
<br></br>
<div id="ctl00_MainContent_PnlConsulta" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_MainContent_BtnBusqueda')">
<div id="ctl00_MainContent_UpnlBusqueda"></div>
<div id="ctl00_MainContent_UpnlResultados">
<div id="ctl00_MainContent_PnlResultados" class="pnlResultados" style="height:auto;display:inline;">
<div id="DivContenedor" class="resultados" style="width: 900px; margin-left: 40px; overflow-x: scroll; height: auto; float: left">
<div id="ContenedorDinamico" style="margin-left: 0px;">
<table class="encabezadoresultado"></table>
<div id="DivPaginas" style="height: auto;">
<div id="masivapg0" class="pgActual"></div>
The div that i am trying to access is
div id="masivapg0" class="pgActual"
I am trying to access the element by the following code, however i always get a false result:
print browser.form(id: 'aspnetForm').div(id: 'cuerpo_principal').div(id: 'cuerpo').div(id: 'ctl00_MainContent_PnlConsulta').div(id: 'ctl00_MainContent_UpnlResultados').div(id: 'ctl00_MainContent_PnlResultados').div(id: 'DivContenedor').div(id: 'ContenedorDinamico').div(id: 'DivPaginas').div(id: 'masivapg0').exist?
But if i search for his parent i always get a true response:
print browser.form(id: 'aspnetForm').div(id: 'cuerpo_principal').div(id: 'cuerpo').div(id: 'ctl00_MainContent_PnlConsulta').div(id: 'ctl00_MainContent_UpnlResultados').div(id: 'ctl00_MainContent_PnlResultados').div(id: 'DivContenedor').div(id: 'ContenedorDinamico').div(id: 'DivPaginas').exist?
Any idea of why could this be happening?
your help is appreciated!
I loaded your html into a file and ran it in watir and, while the browser didn't display anything likely due to the incomplete html code, it didn't have any problem returning true like so:
browser.div(:id => "masivapg0").exists?
#=> true
id tags are supposed to be unique, so you shouldn't have to provide any more selectors than this...

Resources