I am using Selenium with Python. I want to automate to click the one of menu in the dropdown menu written as below. Let's say "openExportDialog()" xpath is //*[#id="globalMenuItems"]/li[1]/a
Could anyone please shed some light?
<div id="nmapGlobalMenu" class="col-md-12 disable-user-select dropdown pr-0 show">
<button class="imgicon n-ui-icon n-ui-ic-operation myBasic_icon imgicon" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></button><div id="globalMenuItems" class="dropdown-menu dropdown-menu-right show" x-placement="bottom-end" style="position: absolute; transform: translate3d(803px, 33px, 0px); top: 0px; left: 0px; will-change: transform;">
</li><li class=""><a class="dropdown-item" onclick="openImportDialog()"><span class="vakata-contextmenu"> Import Node</span></a>
</li><li class=""><a class="dropdown-item" onclick="openExportDialog()"><span class="vakata-contextmenu"> Export Node</span></a>
</li><li class=""><a class="dropdown-item" onclick="discoverNetwork()"><span class="vakata-contextmenu">Discover Network</span></a>
</li><li class=""><a class="dropdown-item" onclick="openEmailSettingsView()"><span class="vakata-contextmenu"> Email Notification Settings</span></a>
</li><li class=""><a class="dropdown-item" onclick="ICMPsettingsView()"><span class="vakata-contextmenu"> ICMP Health Check Settings</span></a>
</li><li class=""><a class="dropdown-item" onclick="customTypeManagement()"><span class="vakata-contextmenu"> Node Type Management</span></a></li></div>
</div>
I hope the question is clear.
Thank you
once the dialog box is open, you can use this //a[#onclick='openExportDialog()'] xpath to click on Export Node option.
Code :
wait = WebDriverWait(driver, 50)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[#onclick='openExportDialog()']"))).click()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
First click on the Button and then try to find the a tag. Like below:
driver find_element_by_id("globalMenuItems").click()
driver.find _element_by_xpath("//a[contains(text(),'Export Node')]").click()
Related
I have a problem with finding element on a webpage. It's a popup window with a confirmation [NO]/[YES]. Selenium can find a parent of a buttons but not a button itself.
Popup window view
HTML block of code:
<div tabindex="-1" role="alertdialog" style="position: fixed; height: auto; width: 300px; top: 188.5px; left: 800px; max-width: 100%;"
class="ui-dialog ui-dialog--notification ui-dialog--modern ui-widget ui-widget-content ui-front ui-dialog-buttons ui-draggable"
aria-describedby="ui-id-3" aria-labelledby="ui-id-4">
<div class="ui-dialog-titlebar ui-corner-all ui-widget-header ui-helper-clearfix ui-draggable-handle"></div>
<div class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; max-height: none; height: 32px;">
<div class="a-AlertMessage">
<div class="a-AlertMessage-body">
<div class="a-AlertMessage-details" id="ui-id-3">Czy chcesz wygenerować pozycje dla całej dostawy?</div>
</div>
</div>
</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><div
class="ui-dialog-buttonset">
<button type="button" class="ui-button ui-corner-all ui-widget">Nie</button>
<button type="button" class="js-confirmBtn ui-button ui-corner-all ui-widget ui-button--hot">Tak</button>
</div>
</div>
</div>
Here is a code snippet that selenium can't find and gives an error 'Unable to locate element':
pop_up_yes_button = driver.find_element(By.XPATH, '//*[#id="t_PageBody"]/div[15]/div[3]/div/button[2]').click()
Parent is avaible for selenium without a problem:
driver.find_element(By.XPATH, '//*[#id="t_PageBody"]/div[15]')
I also tried WebDriverWait and ExpectedConditions but it gives TimeoutException:
WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, '//*[#id="t_PageBody"]/div[15]/div[3]/div/button[2]'))).click()
As you said that it is a popup window, it is very likely that the button is in an iFrame. You have to wait until the iFrame loads and then search the element again.
Luckily, selenium has a built in function for dealing with iFrames:
your_button = WebDriverWait(driver,
20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//*[#id="t_PageBody"]/div[15]/div[3]/div/button[2]')))
your_button.click()
Don't just copy and paste this code, understand this thing and implement it.
I am trying to make an automated checkout system but I can't seem to send keys in fields of this payment box. Even when I try implicit wait and wait for it to load in it still doesn't work.
checkout = driver.find_element_by_id("number")
checkout.send_keys("9848432")
<input required="" autocomplete="cc-number" id="number" name="number" type="tel" aria-describedby="error-for-number tooltip-for-number" data-current-field="number" placeholder="Card number" style="font-family: Roboto, sans-serif; padding: 0.94em 0.8em; transition: padding 0.2s ease-out 0s;">
Here's a link!
Here is the URL you need to fill in the info until you get to the payment page, which is where I am having the issues
It might be in a nested iframe. A similar checkout due to not proper reproducible code.
<iframe src="https://fs.global-e.com/Checkout/v2/598d87e9-cd85-4f61-84df-81e345d62f05?gaSesID=526107767.603750114.583&gaMerchantClientInfo=undefined#undefined&chkcuid=b51f4449-13e2-4883-92ba-2641bb06ec51&isNECAllowed=true&vph=663&ift=87" class="Intrnl_CO_Container" id="Intrnl_CO_Container" name="Intrnl_CO_Container" allowtransparency="true" width="100%" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" height="1000px" style="height: 3101px;">
<iframe id="secureWindow" class="clear-fix clearfix" allowtransparency="true" style="width: 100%; min-height: 160px; height: 165px;" src="https://securev2.global-e.com/payments/CreditCardForm/598d87e9-cd85-4f61-84df-81e345d62f05/11">
<input autocomplete="off" class="form-control input-validation-error" data-type="unknown" data-type-id="1" data-val="true" data-val-luhn="Card number not valid" data-val-luhn-allowempty="False" data-val-luhn-allowspaces="False" data-val-required="Card number" id="cardNum" name="PaymentData.cardNum" pattern="[0-9]{13,16}" placeholder="Card number" type="tel" value="">
</iframe>
</iframe>
Which was solved with:
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'Intrnl_CO_Container')))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'secureWindow')))
checkout = wait.until(EC.presence_of_element_located((By.ID, "cardNum")))
checkout.send_keys("9848432")
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I am attempting to download the data from the following site programmatically with Python: https://health.wyo.gov/publichealth/infectious-disease-epidemiology-unit/disease/novel-coronavirus/covid-19-testing-data/
At the bottom right of the Tableau view there are 3 buttons: Share, Download, and Full Screen. After clicking Download, you are then taken to another pop up. I am then wanting to select Crosstab that then takes you to another pop up where I want to select Positivity and finally, Download which provides a csv.
I have essentially managed to navigate through some of the iframes but am a little lost on where to click since the buttons do not include id/link.
Below is some code from one approach:
from selenium import webdriver
url = 'https://public.tableau.com/profile/melissa.taylor#!/vizhome/WyomingCOVID-19TestingDataDashboard/Dashboard1'
driver = webdriver.Chrome()
driver.get(url)
#elem = driver.switch_to.frame(driver.find_element_by_xpath('//iframe[contains(text(), "googletagmanager"]'))
try:
time.sleep(4)
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to.default_content()
driver.switch_to.frame(iframe)
driver.find_elements_by_tag_name('iframe')
#driver.find_element_by_id('download-ToolbarButton').click()
print(driver.page_source)
finally:
driver.quit()
Below is the HTML that displays the 3 buttons from the Tableau page.
<div class="tab-nonVizItems tab-fill-right hideLabels"><div class="tabToolbarButton tab-widget undo disabled" role="button" data-tb-test-id="undo-ToolbarButton" id="undo-ToolbarButton" aria-disabled="true" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Undo"><span class="tabToolbarButtonImg tab-icon-undo"></span><span class="tabToolbarButtonText">Undo</span></div><div class="tabToolbarButton tab-widget redo disabled" role="button" data-tb-test-id="redo-ToolbarButton" id="redo-ToolbarButton" aria-disabled="true" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Redo"><span class="tabToolbarButtonImg tab-icon-redo"></span><span class="tabToolbarButtonText">Redo</span></div><div class="tabToolbarButton tab-widget revert disabled" role="button" data-tb-test-id="revert-ToolbarButton" id="revert-ToolbarButton" aria-disabled="true" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Reset"><span class="tabToolbarButtonImg tab-icon-revert"></span><span class="tabToolbarButtonText">Reset</span></div><div class="tabToolbarButton tab-widget share" role="button" data-tb-test-id="share-ToolbarButton" id="share-ToolbarButton" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Share"><span class="tabToolbarButtonImg tab-icon-share"></span><span class="tabToolbarButtonText">Share</span></div><div class="tabToolbarButton tab-widget download" role="button" data-tb-test-id="download-ToolbarButton" id="download-ToolbarButton" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Download"><span class="tabToolbarButtonImg tab-icon-download"></span><span class="tabToolbarButtonText">Download</span></div><div class="tabToolbarButton tab-widget enterFullscreen" role="button" data-tb-test-id="toggle-fullscreen-ToolbarButton" id="toggle-fullscreen-ToolbarButton" tabindex="-1" style="user-select: none; -webkit-tap-highlight-color: transparent;" title="Full Screen"><span class="tabToolbarButtonImg tab-icon-enterFullscreen"></span><span class="tabToolbarButtonText">Full Screen</span></div></div>
<div></div></div><div class="tab-ReactView tab-toolbar-dialoghost"></div></div></div>
Thanks for your help!!
Try the below code:
driver.get('https://public.tableau.com/profile/melissa.taylor#!/vizhome/WyomingCOVID-19TestingDataDashboard/Dashboard1')
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='Data Visualization']")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".tab-icon-download"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Crosstab']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='positivity']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Download']"))).click()
Following import:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I have this HTML element code which I am currently struggling to figure out to use it for clicking on the tab that says Problem. As the "Problem" doesnt have a unique classname or element ID, I am unable to figure how to send a Click().
I have tried to check if z-index can be used as index(assumed) and used below line of code
browser.switch_to_frame(a[3])
but it seems I am wrong.
HTML code as below
<div class="TabsViewPort" style="position: relative; overflow: hidden; width: 896px; height: 22px; float: left;">
<div style="overflow: visible; float: left; width: 897px; top: 0px; left: 0px;">
<dl class="OuterOuterTab">
<dd class="OuterTab" artabid="955000038" arwindowid="0" style="top: 1px; z-index: 1; left: 0px; visibility: inherit; display: block;"><span class="TabLeftRounded"> </span>
<span class="Tab">My Profile
</span>
<span class="TabRight"> </span>
</dd>
<dd class="OuterTabSelected" artabid="600000203" arwindowid="0" style="top: 1px; z-index: 3; left: 63px; visibility: inherit; display: block;"><span class="TabLeft"> </span>
<span class="Tab">Approval
</span>
<span class="TabRight"> </span>
</dd>
<dd class="OuterTab" artabid="536870915" arwindowid="0" style="top: 1px; z-index: 1; left: 409px; visibility: inherit; display: block;"><span class="TabLeft"> </span>
<span class="Tab">Problem
</span>
<span class="TabRight"> </span>
</dd>
</dl>
</div>
</div>
The element with text as Problem is a JavaScript enabled element so to click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using XPATH A:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='TabsViewPort']//dl[#class='OuterOuterTab']//dd[#class='OuterTab']//a[#class='btn f1' and text()='Problem']"))).click()
Using XPATH B (shortened):
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='btn f1' and text()='Problem']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
If the element present inside an iframe then you need to switch to iframe first to access the element.
You can Use following method to frame_to_be_available_and_switch_to_it()
By locator ID
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"id of the iframe")))
OR
By locator NAME
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"name of the iframe")))
Once You have switched to iframe you can access the element using following xpath
To click on the element Induce WebDriverWait and element_to_be_clickable()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[#class='Tab']//a[text()='Problem']"))).click()
You need to import following to execute above code.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Hope this will help.
please find below xpath to click on third TAB
(//span[#class="Tab"])[3]/a
I am using Selenium with Python to download certain files from a website. I am trying to access a option called "View all products >>". From there, you could select the kind of file(csv, xlsx) and then you should download it easily. My problem is that I cannot access that "View all products" area. I've tried in so many ways. I'll attach my code and a screenshot with the structure of website. I cannot post entire HTML because it is a website restrictive only to it's paid users.
.
The five links:
1 and 2. (Here "View All Products" appears twice):
<a class="yui3-c-reportdashboardwidget-reportLink" href="./embedded.html?showGDLogo=false#project=/gdc/projects/e05jwlnny6rlxyt5ib9r6479279crrq8&dashboard=/gdc/md/e05jwlnny6rlxyt5ib9r6479279crrq8/obj/4817&tab=8473392139f7&s=/gdc/projects/e05jwlnny6rlxyt5ib9r6479279crrq8|analysisPage|head|/gdc/md/e05jwlnny6rlxyt5ib9r6479279crrq8/obj/3630" title="Headline - View All Products Link" target="_self">Headline - View All Products Link</a>
3 and 4. (Here "View All Products" appears twice):
<span class="yui3-c-reportdashboardwidget-reportLabel" title="Headline - View All Products Link">Headline - View All Products Link</span>
5:
<div class="number" style="font-size: 16px; color: rgb(0, 61, 76);" id="yui_3_14_1_1_1540109592048_72886"> View all products >></div>
The link that I want to handle is number "5", because I think that is the one I need to click(), so that I can download the report afterwards.
My code for this part:
View All Products Button
#product_button = driver.find_elements_by_xpath("//div[#class='c-oneNumberReport yui3-widget yui3-c-onenumberreport yui3-c-onenumberreport-content yui3-widget-content-expanded drillable']")[-1]
#product_button = driver.find_element_by_xpath(("//div[text()='View all products >>']"))
product_button = driver.find_elements_by_xpath("//a[#class='ember-view reportInfoPanelHandle point-to-top']")[-3]
product_button.click()
#product_button.send_keys(Keys.ENTER)
#####actions = ActionChains(driver)
#actions.move_to_element(product_button).send_keys(Keys.ENTER)
###########actions.move_to_element(product_button)
###########actions.click()
#actions.sendKeys(Keys.Return);
#actions.build().perform()
Update::::
Here is the HTML for "Download As..":
<span class="button-text"><script id="metamorph-39-start" type="text/x-placeholder"></script>Download as...<script id="metamorph-39-end" type="text/x-placeholder"></script></span>
HTML for "CSV ( raw data)":
<ul id="ember2849" class="ember-view reportExportMenu gdc-menu-simple" style="position: absolute; top: 106px; left: 15px; z-index: 3005;"><li id="ember2850" class="ember-view reportExportMenuItem">
<a data-ember-action="17"><script id="metamorph-47-start" type="text/x-placeholder"></script>PDF (Portrait)<script id="metamorph-47-end" type="text/x-placeholder"></script></a>
</li><li id="ember2851" class="ember-view reportExportMenuItem">
<a data-ember-action="18"><script id="metamorph-48-start" type="text/x-placeholder"></script>PDF (Landscape)<script id="metamorph-48-end" type="text/x-placeholder"></script></a>
</li><li id="ember2852" class="ember-view reportExportMenuItem">
<a data-ember-action="19"><script id="metamorph-49-start" type="text/x-placeholder"></script>XLSX...<script id="metamorph-49-end" type="text/x-placeholder"></script></a>
</li><li id="ember2853" class="ember-view reportExportMenuItem">
<a data-ember-action="20"><script id="metamorph-50-start" type="text/x-placeholder"></script>CSV (formatted)<script id="metamorph-50-end" type="text/x-placeholder"></script></a>
</li><li id="ember2854" class="ember-view reportExportMenuItem">
<a data-ember-action="21"><script id="metamorph-51-start" type="text/x-placeholder"></script>CSV (raw data)<script id="metamorph-51-end" type="text/x-placeholder"></script></a>
</li></ul>
Try to use below code to click required element:
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
link = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[starts-with(normalize-space(), "View all products")]')))
driver.execute_script("arguments[0].scrollIntoView();", link)
link.click()