How to click random links one by one inside a table - watir

I am automating a site in which I want to click on the links inside a table.
In UI, the table showing like this:
Action Contract Line Item Number Product Product Code
Edit | Del CLI-757042 OpenTable System (Guest Center) SYS010
Edit | Del CLI-757043 Guests Seated from Online GC
I want to click the links CLI-757042,CLI-757043,CLI-757044 one by one. The numbers are random.
Below is the html code:
<!-- WrappingClass -->
<div class="listRelatedObject customnotabBlock"><div class="bPageBlock brandSecondaryBrd secondaryPalette"><div class="pbHeader"> … </div><div id="800f00000006cQt_00Na000000ASdVK_body" class="pbBody"><table class="list" cellspacing="0" cellpadding="0" border="0"><tbody><tr class="headerRow"> … </tr>
<!-- ListRow -->
<tr class="dataRow even first" onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}"><td class="actionColumn"> … </td><th class=" dataCell " scope="row"><a href="/a1if0000000ZfEv">
CLI-757042
</a></th><td class=" dataCell "> … </td><td class=" dataCell "> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell "> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell numericalColumn"> … </td><td class=" dataCell numericalColumn"> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell "> … </td></tr>
<!-- ListRow -->
<tr class="dataRow odd" onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}"><td class="actionColumn"> … </td><th class=" dataCell " scope="row"> … </th><td class=" dataCell "> … </td><td class=" dataCell "> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell "> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell numericalColumn"> … </td><td class=" dataCell numericalColumn"> … </td><td class=" dataCell CurrencyElement"> … </td><td class=" dataCell "> … </td></tr>
<!-- ListRow -->
<tr class="dataRow even" onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}"> … </tr>
<!-- ListRow -->
<tr class="dataRow odd" onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}"> … </tr>
<!-- ListRow -->
<tr class="dataRow even last" onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}"> … </tr></tbody></table><div class="pShowMore"> … </div></div><div class="pbFooter secondaryPalette"> … </div></div></div><div class="listElementBottomNav"></div><script> … </script>
<!-- End ListElement -->
</div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_00Na000000ASdVM" class="bRelatedList"><a name="800f00000006cQt_00Na000000ASdVM_target"></a>
<!-- Begin ListElement -->
<!-- motif: Contract -->
<!-- WrappingClass -->
<div class="listRelatedObject Custom18Block"><div class="bPageBlock brandSecondaryBrd secondaryPalette"><div class="pbHeader"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td class="pbTitle"><img class="minWidth" width="1" height="1" title="" alt="" src="/s.gif"></img><img class="relatedListIcon" title="Order" alt="Order" src="/s.gif"></img><h3 id="800f00000006cQt_00Na000000ASdVM_title"> … </h3></td><td class="pbButton"> … </td><td class="pbHelp"> … </td></tr></tbody></table></div><div id="800f00000006cQt_00Na000000ASdVM_body" class="pbBody"> … </div><div class="pbFooter secondaryPalette"> … </div></div></div><div class="listElementBottomNav"></div><script> … </script>
<!-- End ListElement -->
</div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_00Na000000ASdVR" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_RelatedActivityList" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_RelatedHistoryList" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_00Na000000AT3VB" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_RelatedNoteList" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_00N3000000A6gu9" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<!-- Begin RelatedListElement -->
<div id="800f00000006cQt_RelatedEntityHistoryList" class="bRelatedList"> … </div>
<!-- End RelatedListElement -->
<div class="fewerMore"> … </div><script> … </script>
<!-- Body events -->
<script type="text/javascript"> … </script><div id="datePicker" class="datePicker"> … </div>
<!-- End page content -->
</td></tr></tbody></table></div><div class="bPageFooter noTableFooter"> … </div><div></div></div><script> … </script><script src="/jslibrary/1402506602000/sfdc/ChatterDefer.js" defer="true"></script><script src="/jslibrary/1404472812000/sfdc/Zen.js" defer="true"></script><script> … </script><script async="" defer="" src="/jslibrary/1400606638000/sfdc/SfdcSessionBase190.js"></script><iframe title="sessionserver" style="position: absolute; top: -999px; left: -999px;" src="https://test.salesforce.com/login/sessionserver190.html"></iframe><div id="devSlide" style="display: block;"> … </div><div id="InlineEditDialog" class="overlayDialog cssDialog inlineEditDialog" role="dialog" aria-live="assertive" aria-describedby="InlineEditDialogTitle" style="margin-top: 0px; margin-left: 0px;"> … </div>
When I inspect element in the 1st link it shows table with class=datacell. But there are 2-3 more tables in the page with same class name.

You can use the links method to collect the links and then iterate through the link collection.
Here's a contrived table as an example:
<table class="foo"><tr>
<td>one</td>
<td>two</td>
</tr></table>
<table class="foo"><tr>
<td>three</td>
<td>four</td>
</tr></table>
<table class="bar"><tr>
<td>five</td>
<td>six</td>
</tr></table>
You can collect all the links on the page or target a specific table based on its class attribute or index position.
# print the text attribute for all links
b.links.each { |link| puts link.text}
#=> one
#=> two
#=> three
#=> four
#=> five
#=> six
# print the text attribute for links in the table with a class attribute of "foo"
b.table(:class => "foo").links.each { |link| puts link.text}
#=> one
#=> two
# print the text attribute for links in the table with a index position of 1
b.table(:index => 1).links.each { |link| puts link.text}
#=> three
#=> four
# print the text attribute for links in the table with a class attribute of "bar"
b.table(:class => "bar").links.each { |link| puts link.text}
#=> five
#=> six
In theory--once you've collected the appropriate set of links--you can iterate through the links and click them (although I find this prone to StaleElementReferenceError errors).

Related

Get full XPath itself from partial in Selenium Python

I want to get the text 43,009,500(which is not defined) next to AAAAAA(which text is defined, but the xpath depends on the case)
AAAAAA's XPath : /html/body/table[3]/tbody/tr[10]/td[1]
43,009,500's XPath : /html/body/table[3]/tbody/tr[10]/td[2]
How can I get the full XPath of AAAAAA?
<tr>
<td width="247" height="20" colspan="2">AAAAAA</td>
<td width="105" height="20" align="RIGHT" style="font-size:10pt;">43,009,500</td>
<td width="105" height="20" align="RIGHT" style="font-size:10pt;">-</td>
<td width="104" height="20" align="RIGHT" style="font-size:10pt;">50,009,500</td>
<td width="104" height="20" align="CENTER" style="font-size:10pt;">-</td>
</tr>
x = driver.find_element_by_xpath("//td[text()='AAAAAA").click()
driver.finfind_element_by_xpath(x[:-2]+'2]').text
NoSuchElementException Traceback (most recent call last)
<ipython-input-139-6295b210748f> in <module>
6 driver.find_element_by_xpath("//span[text()='BBBBBB']").click()
----> 7 x = driver.find_element_by_xpath("//td[text()='AAAAAA")
8 driver.finfind_element_by_xpath(x[:-2]+'2]').text

beautiful soup td class name is same and I need to get the value from 1st to 4th value by text

I want to study crawling with selenium and beautiful soup.
I did successfully accessing the website and logged in.
And I tried to get some value by text but it doesn't work.
This is the code that I made.
all3=soup.find("td",{"class": " text-right txt-r"}).text
print(all3)
all4=soup.find("td",{"class": " text-right txt-r"}).text
print(all4)
This is the website coding as follows. I want to get the value from 1st to 4th values by text. However, td class name is same, so I don't know how to get parsing the date with soup.
<td class=" text-right txt-r">7,730</td>
<td class=" text-right txt-r">33,500</td>
<td class=" text-right txt-r">72.8</td>
<td class=" text-right txt-r">88</td>
<td class=" text-right txt-r">0.72%</td>
<td class=" text-right txt-r">0.22%</td>
<td class=" text-center txt-c">높음</td>
<td class=" text-right txt-r">15</td>
I want to make the result as follows.
Print(all3)
Print(all4)
Print(all5)
Print(all6)
7,730, 33,500, 72.8, 88

BeautifulSoup get element inside list except one

I want to get all link value inside a list except one of them.
This is my list:
<ul>
<li>
<a class="link" href="consept link 1">
<svg class="consept" preserveAspectRatio="xMinYMin meet" viewBox="0 0 22 22"><use xlink:href="link"></use></svg>
<h2>Consept title 1</h2>
</a></li>
<li>
<a class="link" href="consept link 2">
<svg class="consept" preserveAspectRatio="xMinYMin meet" viewBox="0 0 22 22"><use xlink:href="link"></use></svg>
<h2>Consept title 2</h2>
</a></li>
<li>
<a class="link" href="consept link 3">
<svg class="consept" preserveAspectRatio="xMinYMin meet" viewBox="0 0 22 22"><use xlink:href="link"></use></svg>
<h2>Consept title 3</h2>
</a></li>
<li>
<a class="link" href="video link">
<svg class="video" preserveAspectRatio="xMinYMin meet" viewBox="0 0 22 22"><use xlink:href="link"></use></svg>
<h2>video title</h2>
</a></li>
</ul>
I want to get link address of parent <svg class="consept"> I mean the a tag but not svg with class video.
expected result:
consept link 1
consept link 2
consept link 3
This worked thanks to a friend.
def _get_all_links(self):
consepts = self.section_bs4.select('consept')
for video_index, post in enumerate(consepts):
consept_url = post.find_parent('a')['href']

dispatchEvent - VBA IE automation

I have a question I can't seem to figure out the answer to regarding how to dispatch an event in VBA.
On the website I am trying to navigate via VBA, there is a dynamic table id="G_grdProfile". In the table html, there are events listed. The table itself is dynamic. At minimum there will always be a row with the id="grdProfile_r_0". Within that row, there are cells that can be clicked. There can be id="grdProfile_rc_0_0", grdProfile_rc_0_1", etc.
I assume I need to dispatch the event in relation to the row or individual cell within the row, but I can't seem to get it to work. From using developer tools in Chrome and IE, it looks like either the ondblclick or onmousedown events are fired when a cell (other than 17) is clicked.
And .click does not return an error, but does not do anything.
My code is:
With ie
While .Busy Or .ReadyState <> 4: DoEvents: Wend
Application.Wait (Now + TimeValue("0:00:02"))
Set objLink = .Document.frames("mainParent").Document.forms("AgentProfileList").Document.getElementById("G_grdProfile").Document.getElementById("grdProfile_r_0").Document.getElementById("grdProfile_rc_0_2")
objLink.dispatchEvent ("onmousedown")
End With
The HTML referenced above for this section is:
<TABLE onmouseup='igtbl_cellClickUp(event,"grdProfile");' onmouseover='igtbl_cellMouseOver(event,"grdProfile");' ondblclick='igtbl_cellDblClick(event,"grdProfile");' onmousemove='igtbl_cellMouseMove(event,"grdProfile");' onmousedown='igtbl_cellClickDown(event,"grdProfile");' onmouseout='igtbl_cellMouseOut(event,"grdProfile");' id=G_grdProfile onselectstart='igtbl_selectStart(event,"grdProfile");' style="WIDTH: 978px; TABLE-LAYOUT: fixed; POSITION: relative" oncontextmenu='igtbl_cellContextMenu(event,"grdProfile");' cellSpacing=0 cellPadding=0 border=0 bandNo="0"><COLGROUP>
<TR id=grdProfile_r_0 style="HEIGHT: 20px" DataKey="XXXXX3658"><TD id=grdProfile_rc_0_0 class="ig_2e49b359_r1 GRSHand"><NOBR><SPAN id=fup_agentstdsearch_3765545><A onclick='javascript:xfupshow("fup_agentstdsearch_3765545");' href="javascript:void(0);"><IMG border=0 src="https://xchange.reged.com/ctiacom/images/flag000.gif"></A></SPAN> </NOBR></TD>
<TD id=grdProfile_rc_0_1 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none" iDV="False"><NOBR><INPUT tabIndex=-1 onpropertychange='igtbl_chkBoxChange(event,"grdProfile");' type=checkbox></NOBR></TD>
<TD id=grdProfile_rc_0_2 class="ig_2e49b359_r1 GRSHand"><NOBR>*LastName*</NOBR></TD>
<TD id=grdProfile_rc_0_3 class="ig_2e49b359_r1 GRSHand"><NOBR>*FIrstName*</NOBR></TD>
<TD id=grdProfile_rc_0_4 class="ig_2e49b359_r1 GRSHand"><NOBR>*MiddleName*</NOBR></TD>
<TD id=grdProfile_rc_0_5 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>3765545</NOBR></TD>
<TD id=grdProfile_rc_0_6 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID*</NOBR></TD>
<TD id=grdProfile_rc_0_7 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID2*</NOBR></TD>
<TD id=grdProfile_rc_0_8 class="ig_2e49b359_r1 GRSHand"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_9 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID3*</NOBR></TD>
<TD id=grdProfile_rc_0_10 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>*ID2*</NOBR></TD>
<TD id=grdProfile_rc_0_11 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>*Location*</NOBR></TD>
<TD id=grdProfile_rc_0_12 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>PROD</NOBR></TD>
<TD id=grdProfile_rc_0_13 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>0</NOBR></TD>
<TD id=grdProfile_rc_0_14 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>7040</NOBR></TD>
<TD id=grdProfile_rc_0_15 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_16 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_17 class="ig_2e49b359_r1 GRSHand"><NOBR><A onclick="viewProfile('3765545','*LastName* *FirstName*');" href="javascript:void(0);">View Profile Summary</A></NOBR></TD>
<TD id=grdProfile_rc_0_18 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_19 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_20 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD>
<TD id=grdProfile_rc_0_21 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR> </NOBR></TD></TR>
Any ideas, or am I even using dispatchEvent properly?
I figured out what needed to occur was a few mouse events had to fire to move forward.
I ended up setting the cell in the table that I wanted to click and used fireEvent to fire all of the onmouse* events that had to happen.
Set objLink = IE1.document.frames("mainParent").document.forms("AgentProfileList").document.getElementById("grdProfile_r_0").document.getElementById("grdProfile_rc_0_2")
objLink.fireEvent ("onmouseover")
objLink.fireEvent ("onmousedown")
objLink.fireEvent ("onmouseup")

Make correct layout for TextView and ImageView

What Layouts need use for make this?
HTML
<h1>Title</h1>
<div id="itemWrapper">
<div class="item">
<div class="png">
<img src="xxx.png">
</div>
<div class="text">
text text text text text text text text text text
</div>
</div>
<div class="item">
<div class="png">
<img src="xxx.png">
</div>
<div class="text">
text text text text text text text text text text
</div>
</div>
<div class="item">
<div class="png">
<img src="xxx.png">
</div>
<div class="text">
text text text text text text text text text text
</div>
</div>
<div class="item">
<div class="png">
<img src="xxx.png">
</div>
<div class="text">
text text text text text text text text text text
</div>
</div>
</div>
CSS
.item{clear:both;}
.item .png{float:left;height:50px}
.item .text{float:left;height:50px}
h1{text-align:center}

Resources