Consider:
<tr id="pair_12">
<td class="left first">
<span class="ceFlags USD"> </span>
USD
</td>
<td class="" id="last_12_12">1</td>
<td class="pid-2124-last" id="last_12_17">0,8979</td>
<td class="pid-2126-last" id="last_12_3">0,7695</td>
<td class="pid-3-last" id="last_12_2">109,94</td>
<td class="pid-4-last" id="last_12_4">0,9708</td>
<td class="pid-7-last" id="last_12_15">1,3060</td>
<td class="pid-2091-last greenBg" id="last_12_1">1,4481</td>
<td class="pid-18-last greenBg" id="last_12_9">5,8637</td>
</tr>
I want to access, for example, the "5,8637" value and it also refreshes for every other second or so. Here is the website maybe it helps you to help me better link.
driver = Chrome(webdriver)
driver.get("https://tr.investing.com/currencies/exchange-rates-table")
eur_usd = driver.find_element_by_id("last_17_12").text
worked for me!
Use:
By id = By.id("ANY_ID");
Use the getText(id); function under Selenium WebDriver.
Related
I am trying to get a list that matches India's districts to its district codes as they were during the 2011 population census. Below I will post a small subset of the outerHTML I copied from a government website. I am trying to loop over it and extract a string and an int from each little html box and store these ideally in a pandas dataframe on the same row. The HTML blocks look like this, I represent 2, there are around 700 in my txt file:
<tr>
<td width="5%">1</td>
<td>603</td>
<td align="left">**NICOBARS**</td>
<td align="left">NICOBARS </td>
<td align="left">ANDAMAN AND NICOBAR ISLANDS(State)</td>
<td align="left">NIC</td>
<td align="left">02</td>
<td align="left">**638**</td>
<td align="left">
Not Covered
</td>
<td width="5%" align="center"><i class="fa fa-eye" aria-hidden="true"></i>
</td>
<td width="5%" align="center"><i class="fa fa-history" aria-hidden="true"></i>
</td>
<td width="5%" align="center">
</td>
<td width="3%" align="center">
<!-- Merging issue revert beck 05/10/2017 -->
<i class="fa fa-map-marker" aria-hidden="true"></i>
</td>
</tr>
<tr>
<td width="5%">2</td>
<td>632</td>
<td align="left">**NORTH AND MIDDLE ANDAMAN**</td>
<td align="left">NORTH AND MIDDLE ANDAMAN </td>
<td align="left">ANDAMAN AND NICOBAR ISLANDS(State)</td>
<td align="left">NMA</td>
<td align="left"></td>
<td align="left">**639**</td>
<td align="left">
Not Covered
I have put ** around ** the values that I want to get from the text file. I was wonder how I could loop through this text to extract this data. I thought about start counting each time after I encounter and than extract the data of the 1st and 6st but I don't know how to code this. Hope anyone is willing to help out. Or maybe anyone who already has this list, would be great!
If you're able to get the text of the entire html table, you can use df = pd.read_html(html_text_string). 50% of the time, it works everytime!
pd.read_html <-- docs
I'm trying to do automation and struck in the middle.
Cannot able to select option from a submenu.
Tried every solution from stack overflow and anything doesn't work.
Attaching the code.
<input id="arid_WIN_0_2000053" class="text " readonly="" style="top: 0px; left: 0px; width: 72px; height: 21px;" title="Screen" type="text">
This is the id i need to click so a drop down appears.
That is from differant section and the code is,
<table class="MenuTable" style="width: 93px;" cellspacing="0" cellpadding="0">
<tbody class="MenuTableBody">
<tr class="MenuTableRow">
<td class="MenuEntryName" nowrap="">Screen</td>
<td class="MenuEntryNoSub" arvalue="Screen"></td>
</tr>
<tr class="MenuTableRow">
<td class="MenuEntryName" nowrap="">File</td>
<td class="MenuEntryNoSub" arvalue="File"></td>
</tr>
<tr class="MenuTableRow">
<td class="MenuEntryName" nowrap="">Printer</td>
<td class="MenuEntryNoSub" arvalue="Printer"></td>
</tr>
<tr class="MenuTableRow">
<td class="MenuEntryNameHover" nowrap="">(clear)</td>
<td class="MenuEntryNoSubHover" arvalue=""></td>
</tr>
</tbody>
</table>
Once i selected the ID arid_WIN_0_2000053, i need to select option as File.
Thanks in advance.
As per the HTML to select an option e.g. File from the submenu you can use either of the following solutions:
driver.find_element_by_xpath("//input[#class='text' and #title='Screen'][starts-with(#id,'arid_WIN_0_')]").click()
driver.find_element_by_xpath("//table[#class='MenuTable']//tr[#class='MenuTableRow']//td[#class='MenuEntryName' and contains(.,'File')]").click()
Or
driver.find_element_by_xpath("//input[#class='text' and #title='Screen'][starts-with(#id,'arid_WIN_0_')]").click()
driver.find_element_by_xpath("//table[#class='MenuTable']//tr[#class='MenuTableRow']//td[#class='MenuEntryNoSub' and #arvalue='File']").click()
Use as Css locator : .MenuTableRow:nth-of-type(2) .MenuEntryName
I am trying to locate a specific element with XPath (for a script that I work on in Python with Selenium module). I've looked it up on the internet but I can't find solution to my problem, which is:
there is a table that consists of many 'tr'. Each 'tr' consist of couple 'td' that share the same class (namely:"Zelle"). I'd like to find a 'tr' that meets two conditions. First it has to contain text "auto" in one td, then it has to contain text "Abge" in ANOTHER td- finally it has to contain "a" element of class "Tabelle".
I wrote something like this:
("//tr//td[#class='Zelle'][contains(.,'auto')]//following::td[#class='Zelle'][contains(.,'Abge')]//following::a[#class='Tabelle']")
But when I try it in developers console I get all tr's with td that contain "auto" (even if the second td doesn't contain "Abge"). How to write statement that would return ONLY tr's with BOTH "auto" and "Abge"?
Sample HTML:
<tr>
<td class="Zelle">auto</td>
<td class="Zelle">Abge</td>
<td class="Zelle">Some characters</td>
<td class="Zelle">
<a class="Tabelle" href="blablahblah.aspx?xxxx=Number"></a></td>
</tr>
<tr>
<td class="Zelle">auto</td>
<td class="Zelle">Abge</td>
<td class="Zelle">Some characters</td>
<td class="Zelle">
<a class="Tabelle" href="blablahblah.aspx?xxxx=Number"></a></td>
</tr>
<tr>
<td class="Zelle">auto</td>
<td class="Zelle">Some text(but no "Abge")</td>
<td class="Zelle">Some characters</td>
<td class="Zelle">
<a class="Tabelle" href="blablahblah.aspx?xxxx=Number"></a></td>
</tr>
<tr>
<td class="Zelle">some text (but not "auto")</td>
<td class="Zelle">Abge</td>
<td class="Zelle">Some characters</td>
<td class="Zelle">
<a class="Tabelle" href="blablahblah.aspx?xxxx=Number"></a></td>
</tr>
Try to use below XPath
//tr[td[contains(., "auto")] and td[contains(., "Abge")] and .//a[#class="Tabelle"]]
I have the following HTML:
<tbody role="alert" aria-live="polite" aria-relevant="all"
<tr class="odd">
<td class="">program user</td>
<td class="">program pass</td>
<td class="">program email</td>
<td class="">Program User</td>
<td class="">
<span class="ui-icon ui-icon-closethick"></span>
</td>
</tr>
<tr class="even">
<td class="">progman</td>
<td class="">progman_name</td>
<td class="">progman_lastname</td>
<td class="">Program Manager</td>
<td class="">
<span class="ui-icon ui-icon-closethick"></span>
This displays a table of users and:
<span class="ui-icon ui-icon-closethick"></span>
is the button 'x', which I am trying to locate so I can delete the user, a specific user 'Program Manager' or 'Program User'
Is this possible?
I assume that you are trying to find a specific user (for which you already know the name) and click on the associated delete button. Something like this should work:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("your-url-here")
elem = driver.find_element_by_xpath("//tbody/td[text()='your-name-here']/../span")
elem.click()
driver.close()
Well I found the solution:
one = driver.find_element_by_xpath("//td[#class='' and text()='Program Manger']/..//span[#class='ui-icon ui-icon-closethick']")
ActionChains(driver).double_click(one).perform()
Basically the I find the class containing text "Program Manager" then I move up to its parent, then iteratively ie. with // look for the 'ui-icon ui-icon-closethick'
And it worked!
I have html document with table like:
<tr>
<td width="3%"><input type="checkbox", name="chk"></td>
<td width="10%">101</td>
<td width="4%">Fix</td>
<td width="5%">2.00</td>
<td width="6%">09:28:03</td>
<td width="5%">5</td>
<td width="9%">6026866.421</td>
<td width="9%">6525118.804</td>
<td width="5%">149.124</td>
<td width="8%">3533692.676</td>
<td width="8%">1174580.462</td>
<td width="8%">5161083.095</td>
<td width="5%">0.009</td>
<td width="5%">0.016</td>
<td width="5%">2.14</td>
<td width="7%">07/09</td></tr>
<br>
<tr>
<td width="3%"><input type="checkbox", name="chk"></td>
<td width="10%">101</td>
<td width="4%">Fix</td>
<td width="5%">0.00</td>
<td width="6%">09:28:03</td>
<td width="5%">5</td>
<td width="9%">6026866.421</td>
<td width="9%">6525118.804</td>
<td width="5%">149.124</td>
<td width="8%">3533692.676</td>
<td width="8%">1174580.462</td>
<td width="8%">5161083.095</td>
<td width="5%">0.009</td>
<td width="5%">0.016</td>
<td width="5%">2.14</td>
<td width="7%">07/09</td></tr>
and so on....
I need to remove rows where the fourth cell content is '0.00' and leave
only these with '2.00' or maybe would be easier to remove only even rows.
what is the most simple way to achieve it using python?
Using Beautiful Soup (this is just a start, there's much to improve, like how to check for zero and you also have to make up your mind if you want to check the third or the fourth cell):
soup = BeautifulSoup(open('yourhtml.html').read())
for tr in soup('tr'):
if tr('td')[3].text == '0.00':
tr.extract()
You might want to look at Beautiful Soup, a python parser for HTML and XML.