I'm having trouble finding elements by xpath or id inside of outlook's online html. I'm using selenium and python. Here is what I've wrote.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException #imports
browser = webdriver.Chrome('C:\\Users\\...')
browser.get('https://www.office.com/...') #setup
#then some code to sign into outlook online
browser.find_element_by_xpath('//*[#id="_ariaId_64"]/div/div/div[1]')
browser.find_element_by_xpath('//*[#id="MailFolderPane.FavoritesFolders"]/div[19]')
browser.find_element_by_id('_ariaId_68') #attempts to find an element in outlook
this is the element I'm trying to access. I would post the entire html, but there is just so much. I'm brand new to all things code so go easy on me :)
<div>
<div id="_ariaId_68" aria-expanded="false" draggable="true" dropzone="string:text/plain">
<div autoid="_n_R" class="_n_44 canShowFavoritesAction" role="treeitem" aria-expanded="false" aria-labelledby="_ariaId_68.folder _ariaId_68.ucount" aria-haspopup="true" tabindex="-1">
<div class="_n_S3 nowrap border-color-transparent _n_X3" style="padding-left: 4px;">
<div class="_n_V3 _n_54">
<span autoid="_n_S" class="_n_W3 ms-font-m ms-fwt-sl _n_Y3" id="_ariaId_68.folder" title="Sent Items">Sent Items</span>
<div class="_n_24 ms-bg-color-neutralLighter"> <span autoid="_n_T" class="ms-font-m _n_Z3 ms-fwt-sb ms-fcl-tp" aria-hidden="true"></span> </div>
<span class="ms-font-s ms-fcl-ns" aria-hidden="true" aria-expanded="false" aria-haspopup="true" tabindex="-1"> </span> <button autoid="_n_U" type="button" class="_n_34 ms-fwt-r ms-fcl-ns o365button hidden" style="display: none;" tabindex="-1"></button> <span style="display: none;" aria-hidden="true"></span>
</div>
<div class="_n_14 hidden"><button autoid="_n_V" type="button" class="_n_04 firefoxFavorite o365button" title="Remove from Favorites" aria-labelledby="_ariaId_69"><span class="_fc_3 owaimg ms-Icon--star ms-icon-font-size-18 ms-fcl-ns-b"> </span><span class="_fc_4 o365buttonLabel _fc_2" id="_ariaId_69" style="display: none;"></span></button></div>
</div>
</div>
</div>
</div>
Assuming you're trying to find the SENT ITEMS's - web element.
The SENT ITEM link does not seem to be the visible area [when you have more sub folders inside Inbox, this usually happens] and hence you first make a scroll to view to the element before performing anything on the element.
Here are the options to bring the element to visible area
Try with following xpath
//span[#title='Sent Items']
Related
So I am automating with selenium and running into an issue where everytime I refresh a page, the element ID changes, no matter if I copy XPATH, CSS Selector, ID, they all have a number in them that changes.
so the code I'm using is simple, I just want to click the button which I can accomplish with
browser.find_element(by=By.CSS_SELECTOR, value='*VALUE HERE*').click()
But I don't know what to put as the value.
Here is the HTLM code
<a class="x4-tab x4-unselectable x4-box-item x4-tab-default x4-noicon x4-tab-noicon x4-tab-default-noicon x4-top x4-tab-top x4-tab-default-top x4-tab-after-title x4-active x4-tab-active x4-tab-default-active x4-top-active x4-tab-top-active x4-tab-default-top-active" hidefocus="on" unselectable="on" id="tab-1965" tabindex="0" data-ui-comp-name="wm-np-tab-wrkstn" style="right: auto; left: 66px; margin: 0px; top: 0px;">
<span id="tab-1965-btnWrap" role="presentation" class="x4-tab-wrap" unselectable="on">
<span id="tab-1965-btnEl" class="x4-tab-button" role="presentation">
<span id="tab-1965-btnInnerEl" class="x4-tab-inner x4-tab-inner-center"
unselectable="on">Workstations</span>
<span role="presentation" id="tab-1965-btnIconEl" class="x4-tab-icon-el " unselectable="on"
style="">
</span>
</span>
</span>
</a>
If you look at the HTML, anywhere you see that number 1965, that number will change if the page is refreshed. How do I make selenium find this element no matter what that number is?
Also, not sure if this matters but this is all in an iframe which I have selenium target by using
frame1 = browser.find_element(by=By.CLASS_NAME, value='defaultView')
browser.switch_to.frame(frame1)
Also, another problem is that HTML code is almost identical to other buttons, the only differences between the buttons is that number (that changes) and where is says "Workstations". Here is an example of another button that is next to it, this one is for servers.
<span id="tab-1964-btnWrap" role="presentation" class="x4-tab-wrap" unselectable="on">
<span id="tab-1964-btnEl" class="x4-tab-button" role="presentation">
<span id="tab-1964-btnInnerEl" class="x4-tab-inner x4-tab-inner-center"
unselectable="on">Servers</span>
<span role="presentation" id="tab-1964-btnIconEl" class="x4-tab-icon-el"
unselectable="on" style="">
</span>
</span>
</span>
</a>
You can use XPath for this:
browser.find_element(by=By.XPATH, value="//span[starts-with(#id, 'tab-') and contains(#id, '-btnEl')]").click()
I am designing a bot which will shortlist and send mail to specific candidates on the basis of resume database. A website with a collection of resumes and user can search related resumes on the basis of keywords and location.
With chrome Driver and selenium I got upto a point where entering keyword and location website shows some results. Here is the point where I am having problem
driver.find_elements_by(class_name, css_selector, name, tag_name, xpath) I tried all of them to retrieve the list of results and corresponding items like, name of candidate, email, id_of_that_resume and also need to handle if I already have sent the candidate invitation mail or not.
It will be a great favor if you answer with the code. Thanks in advance
this is the image corresponding to the inspected element alongwith the search result of resume against keyword
<div class="col-xs-12 tuple ng-scope" data-ng-class="resumeCtrl.GetCssClass(item.Status)" ng-repeat="item in resumeCtrl.items | limitTo: resumeCtrl.limitToValue track by $index" ng-show="resumeCtrl.items.length > 0" style="">
<div class="checkbox" style="margin-top: 57px;">
<input id="chk131545341" name="resumerowcheckbox" type="checkbox" onchange="global.isChecked(this);" ng-click="resumeCtrl.isAllChecked()" ng-checked="" data-itemid="131545341" data-isviewed="false" data-itemtitle="Dimple AXXXXXXX" data-itemcity="" data-statustext="" data-itemstatuscd="" data-documentid="131545341" data-firstname="Dimple">
<label for="chk131545341"></label>
</div>
<div class="tuple-body mob-qs-wrap">
<div class="col-xs-2 quick-section text-right pull-right visible-xs"><a class="quicklinks pull-right"><i class="fa fa-ellipsis-v fa-2x"></i></a></div>
<div class="tuple-col col-xs-10 col-sm-6 info">
<h3 data-isviewed="false" class="tuple-title">
<span class="link ng-binding" ng-click="resumeCtrl.ShowResume(item,resumeCtrl.FromRange+$index);">Dimple A</span>
</h3>
<address class="h5 text-dark-gray">
<span data-ng-show="resumeCtrl.showLocationInfo(item)" class="ng-binding ng-hide">, </span>
<span data-ng-show="resumeCtrl.showMilesInfo(item)" class="ng-binding ng-hide"> - miles</span>
</address>
<!-- ngIf: resumeCtrl.showExperienceInfo(item.Experience) --><ul class="list-info text-dark-gray h5 ng-scope" data-ng-if="resumeCtrl.showExperienceInfo(item.Experience)">
<li class="ng-binding">Last Active: 01/07/2020</li>
<li class="ng-binding">Work Experience: 20 years 1 month</li>
</ul><!-- end ngIf: resumeCtrl.showExperienceInfo(item.Experience) -->
<!-- ngIf: !resumeCtrl.showExperienceInfo(item.Experience) -->
<p class="mt15 text-dark-gray fs12 hidden-xs p0 ng-binding" data-ng-bind-html="item.HighlightingSnippet | to_trusted">Enterprise Applications and Database Development using , <strong>Python</strong>... . Hands on experience in data processing automation using <strong>python</strong> .... patterns . Web development...</p>
</div>
<div class="tuple-col col-xs-10 col-sm-4 hidden-xs">
<a data-ng-click="resumeCtrl.ShowResume(item,resumeCtrl.FromRange+$index)" data-preview="preview" class="btn btn-primary preview">Reviewed</a>
<span class="h5 ng-hide" data-ng-show="item.IsViewed">Last viewed </span>
</div>
<div class="tuple-col col-xs-10 col-sm-2 hidden-xs quick-section mob-quick-section">
<div class="action-toggle">
<button class="btn btn-default bg-default" data-toggle="dropdown"><span class="text">Actions<i class="caret"></i></span></button>
<ul class="action-menu dropdown-menu">
<!-- Start Forcefull link add-on for mobile view, should REFRAIN taking this approach -->
<li class="hide">
<a data-ng-click="resumeCtrl.ShowResume(item);" data-preview="preview" class="link quicklinks ng-binding" data-maction="PRVW">
<span class="fa-icon-width"><i class="fa fa-file-text-o"></i></span>Preview Resume
<span class="h5 text-gray ml25 mb10 lht1 ng-hide" data-ng-show="item.IsViewed">Last viewed </span>
</a>
</li>
<!-- End Forcefull link add-on for mobile view, should REFRAIN taking this approach -->
<li><a class="link quicklinks" data-maction="INVT" data-ng-click="resumeCtrl.InviteToApply(item, 'Rimeiko Lyles');"><span class="fa-icon-width"><i class="fa fa-envelope"></i></span><span class="quick-text">Invite to Apply</span></a></li>
<li><a class="link quicklinks" data-maction="ADCN" data-ng-click="resumeCtrl.AddCandidateToJob(item, 'Rimeiko Lyles');"><span class="fa-icon-width"><i class="fa fa-user-plus"></i></span><span class="quick-text">Add Candidate to Job</span></a></li>
<li><a class="link quicklinks" data-maction="DNLP" data-ng-click="resumeCtrl.DownloadResume(item, 'pdf')"><span class="fa-icon-width"><i class="fa fa-file-pdf-o"></i></span><span class="quick-text">Download to PDF</span></a></li>
<li><a class="link quicklinks" data-maction="DNLD" data-ng-click="resumeCtrl.DownloadResume(item, 'docx')"><span class="fa-icon-width"><i class="fa fa-file-word-o"></i></span><span class="quick-text">Download to MS Word</span></a></li>
</ul>
</div>
</div>
</div>
</div>
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
#assuming you defined driver already.
some_elements = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located(
(By.XPATH, "//div[#data-ng-class='resumeCtrl.GetCssClass(item.Status)']")))
for element in some_elements:
print("element.text:", element.text)
Or
same_elements = driver.find_elements_by_xpath("//div[#data-ng-class='resumeCtrl.GetCssClass(item.Status)']")
for element in same_elements:
print("same_element.text:", element.text)
I want to select a checkbox using selenium in python. Following is the HTML of the checkbox. The span element is getting highlighted when hovering the mouse over checkbox
HTML
<div id="rc-anchor-container" class="rc-anchor rc-anchor-normal rc-anchor-light">
<div id="recaptcha-accessible-status" class="rc-anchor-aria-status" aria-hidden="true">Recaptcha requires verification. </div>
<div class="rc-anchor-error-msg-container" style="display:none"><span class="rc-anchor-error-msg" aria-hidden="true"></span></div>
<div class="rc-anchor-content">
<div class="rc-inline-block">
<div class="rc-anchor-center-container">
<div class="rc-anchor-center-item rc-anchor-checkbox-holder"><span class="recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox" role="checkbox" aria-checked="false" id="recaptcha-anchor" tabindex="0" dir="ltr" aria-labelledby="recaptcha-anchor-label"><div class="recaptcha-checkbox-border" role="presentation"></div><div class="recaptcha-checkbox-borderAnimation" role="presentation"></div><div class="recaptcha-checkbox-spinner" role="presentation"></div><div class="recaptcha-checkbox-spinnerAnimation" role="presentation"></div><div class="recaptcha-checkbox-checkmark" role="presentation"></div></span></div>
</div>
</div>
<div class="rc-inline-block">
<div class="rc-anchor-center-container">
<label class="rc-anchor-center-item rc-anchor-checkbox-label" aria-hidden="true" role="presentation" id="recaptcha-anchor-label"><span aria-live="polite" aria-labelledby="recaptcha-accessible-status"></span>I'm not a robot</label>
</div>
</div>
</div>
<div class="rc-anchor-normal-footer">
<div class="rc-anchor-logo-portrait" aria-hidden="true" role="presentation">
<div class="rc-anchor-logo-img rc-anchor-logo-img-portrait"></div>
<div class="rc-anchor-logo-text">reCAPTCHA</div>
</div>
<div class="rc-anchor-pt">Privacy<span aria-hidden="true" role="presentation"> - </span>Terms</div>
</div>
</div>
I am trying the following code but it is giving following exception selenium.common.exceptions.NoSuchElementException
My Code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = 'C:\Program Files (x86)\Google\Chrome\chromedriver'
browser = webdriver.Chrome(chromedriver)
browser.get(url)
checkBox = browser.find_element_by_id("recaptcha-anchor")
checkBox.click()
This is a recaptha stuff .. it's not like normal elements in the page
you have to navigate with selenium to the captcha frame .. then you can deal with the checkbox element..
to do that you need first to save the main window handle to be get back to it when you're done with the recaptcha
# save the main window handle
mainwindow = browser.current_window_handle
# get the recapthca iframe then navigate to it
frame = browser.find_element_by_tag_name("iframe")
browser.switch_to.frame(frame)
# now you can access the checkbox element
browser.find_element_by_id("recaptcha-anchor").click()
# navigate back to main window
browser.switch_to.window(mainwindow)
for further info about how to deal with the recaptcha challenge check this link
I want to make an automated Gmail account creator. For some reason, I am not being able to web driver to click on the month and choose a month to proceed with the creation.I'm using an earlier version of selenium(2.4) and Firefox(25) because of having problems with gecko driver.
<label id="month-label" class="month">
<span id="BirthMonth" class=" form-error" aria-invalid="true">
<div class="goog-inline-block goog-flat-menu-button jfk-select" role="listbox" style="-moz-user-select: none;" aria-expanded="false" tabindex="0" aria-haspopup="true" title="Birthday" aria-activedescendant=":0">
<div id=":0" class="goog-inline-block goog-flat-menu-button-caption" role="option" aria-setsize="12" aria-posinset="0"> … </div>
<div class="goog-inline-block goog-flat-menu-button-dropdown" aria-hidden="true"> … </div>
</div>
<input id="HiddenBirthMonth" type="hidden" name="BirthMonth"></input>
</span>
</label>
I have filled all of the earlier fields which didn't require a dropdown.
birthelem2=(browser.find_element_by_id('BirthMonth'))
birthelem2.click()
month=browser.find_elements_by_class_name('goog-menuitem-content')
month[0].click()
I expect it to choose a month(January)
<div id="crmMasthead" tabindex="-1">
<div id="crmTopBar" class="ms-crm-TopBarContainer ms-crm-TopBarContainerGlobal newNavBarMode">
<div id="crmAppMessageBar" class="crmAppMessageBar" style="display: none; height: 0px;">
<div id="crmRibbonManager" currentribbonelement="commandContainer15" style="height: 62px; display: block; visibility: visible;">
<div id="commandContainer15" style="display: inline;">
<ul class="ms-crm-CommandBar-Menu" role="application">
<li id="ewrb_importfile|NoRelationship|HomePageGrid|Mscrm.HomepageGrid.ewrb_importfile.NewRecord" class="ms-crm-CommandBarItem ms-crm-CommandBar-Menu ms-crm-CommandBar-Button" tabindex="-1" title="New Create a new Import File record." command="ewrb_importfile|NoRelationship|HomePageGrid|Mscrm.NewRecordFromGrid" style="white-space: pre-line; display: inline-block;">
<span class="ms-crm-CommandBar-Button ms-crm-Menu-Label-Hovered" tabindex="-1" style="max-width:200px">
<a class="ms-crm-Menu-Label" tabindex="0" onclick="return false">
<img class="ms-crm-ImageStrip-New_16 ms-crm-commandbar-image16by16" tabindex="-1" src="/_imgs/imagestrips/transparent_spacer.gif" style="vertical-align:top"/>
<span class="ms-crm-CommandBar-Menu" tabindex="-1" style="max-width:150px" command="ewrb_importfile|NoRelationship|HomePageGrid|Mscrm.NewRecordFromGrid"> New </span>
<div class="ms-crm-div-NotVisible"> Create a new Import File record. </div>
</a>
</span>
</li>
The Xpath Shows me like this:
.//*[#id='ewrb_importfile|NoRelationship|HomePageGrid|Mscrm.HomepageGrid.ewrb_importfile.NewRecord']/span/a
and If i use this, Selenium doesn't click the button
First try to remove "."(dot) from your xpath and check it if it works.
Secondly, try to write the xpath yourself. For this a node, try this one:
//a[#class="ms-crm-Menu-Label"]
You should check it if the part of html that you share is inside an iframe node or not. Otherwise, you should share more. With the current part that you shared, it is not possible to say that if it is inside an iframe or not.
Also, it can be a good idea to check the visibility of the button. The last thing: do you receive any error message. If yes, share it.