https://gyazo.com/9887635aa04d723758ba17b3413f72e1 - the html
the one named class="radio inline bundle-cta" is the one i want.
<label class="radio inline bundle-cta">
<input data-bind="checked: activeBundle" id="BundleType" name="BundleType" type="radio" value="Default">
Nej tak, jeg vælger en basisannonce uden tilvalg
<span class="uneditable-input price">Kr. <span data-price="0">0</span>,-</span>
<span class="bundle-cta-button">Vælg basisannonce</span>
</label>
error msg, when trying to click it:
Element is not clickable at point (604, 698). Other element would receive the click: <p style="line-height: 20px; margin: 0px 40px 0px 15px; padding: 0px;">...</p>
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64)
code I used to try to click it:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.class, "bundle-cta-button"))
# vælg gratis pakke
browser.find_element_by_class_name('bundle-cta-button').click()
sleep(0.75)
browser.find_element_by_xpath('//*[#id="content"]/div[2]/div/div/form/div/button').click()
Try to change spaces into dots, and find by CSS_selector like below:
browser.find_element_by_css_selector("radio.inline.bundle-cta").click()
Related
Code trials:
import selenium
from selenium import webdriver
PATH = 'C:\Program Files (x86)\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://oncf-voyages.ma")
origin = driver.find_elements_by_xpath('/html/body/div[1]/section/div[1]/div[2]/main/div[1]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div/div/div[2]/div/input')
origin.send_keys("something")
origin.send_keys(Keys.RETURN)
I used the python code above to try and practice some basic operations with selenium but I can't access an input clause
Here's the website that I'm working on : https://www.oncf-voyages.ma/
This is a part of the html code of the website:
<div class="ant-col SearchForm_col ant-col-xs-24 ant-col-md-24 ant-col-xl-24 ant-col-xxl-24" style="padding-left: 15px; padding-right: 15px;"><label class="SearchForm_label">Ma gare de départ</label><div class="InputWrapper"><div id="origin" class="SelectPicker SelectWidget ant-select ant-select-enabled"><div class="ant-select-selection
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="b5b887d5-0fcf-488c-dc1a-9dca53b48787" aria-expanded="false" tabindex="0"><div class="ant-select-selection__rendered"><div unselectable="on" class="ant-select-selection__placeholder" style="display: block; user-select: none;">Ma gare de départ</div><div class="ant-select-search ant-select-search--inline" style="display: none;"><div class="ant-select-search__field__wrap"><input id="origin" autocomplete="off" class="ant-select-search__field" value=""><span class="ant-select-search__field__mirror"> </span></div></div></div><span class="ant-select-arrow" unselectable="on" style="user-select: none;"><i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></div></div></div></div>
The <input> with you are trying to locate with the xpath:
/html/body/div[1]/section/div[1]/div[2]/main/div[1]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/div[1]/div[1]/div[2]/div/div[1]/div/div/div/div/div[2]/div/input
is within it's ancestor <div> with style attribute set as display: none;
So Selenium won't be able to interact with the element unless it's visible, enabled and interactable(clickable).
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-imageModel" style="display: block; z-index: 1002; outline: 0px; height: auto; width: 700px; top: 225.5px; left: 278.5px;"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" id="ui-dialog-title-imageModel">ATTENTION TAX PAYERS!!!!!</span><span class="ui-icon ui-icon-closethick">close</span></div><div id="imageModel" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 92.4px;" scrolltop="0" scrollleft="0">
<ul><li class="redFont"> Please insist on getting Form 16/16A from your Deductor downloaded only from Traces.Valid form 16/16A.<i><u> click here.</u></i></li></ul>
<div class="floatLeft margintop20"><input type="checkbox" id="Details" name="Details" onclick="checkModal('modalPagee')"> I agree to the usage and acceptance of Form 16 / 16A generated from TRACES</div>
<div class="floatLeft margintop20">
<input value="Proceed" type="button" class="button" id="btn" disabled="disabled" onclick="goCancel()">
</div>
</div></div>
This is the HTML code on which I am working, Here I want to select the input element of type checkbox, when I was trying it as
check_box = find_element_by_id("Details").click() I was failing to select it .
if need of more details in
"https://www.incometax.gov.in/iec/foportal" please visit this site,
when after login, goto -> e-file -> income_tax_returns -> view for 26as and continue, Then we will get another window opened and will get a popup here in pop up we need to select the checkbox.
That details is in new tab, you need to switch the focus like below :
wait = WebDriverWait(driver, 10)
new_handle = driver.window_handles
print(len(new_handle))
driver.switch_to.window(new_handle[1])
wait.until(EC.element_to_be_clickable((By.ID, "Details"))).click()
Try:
check_box = find_element_by_xpath('//*[#id="Details"]').click()
I'm attempting to upload a file into a form, but there is no input element with the type of "file".
I'm able to remove the "readonly" attribute and send keys to the input text box, but it throws a general error when I click the upload button. (just a popup with no useful information)
This is the element as presented:
<input type="text" autocomplete="off" class="form-control animate-show
ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched"
id="filepath" ng-model="model.name" ng-required="configuration.Required"
readonly="" required="required" style="">
This is the element after selecting a file manually:
<input type="text" autocomplete="off" class="form-control animate-show
ng-pristine ng-touched ng-not-empty ng-valid ng-valid-required"
id="filepath" ng-model="model.name" ng-required="configuration.Required"
readonly="" required="required" style="">
This is the element after removing "readonly" and sending my file path via selenium:
<input type="text" autocomplete="off" class="form-control animate-show
ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required"
id="filepath" ng-model="model.name"
ng-required="configuration.Required" required="required" style="">
Test setup:
Ubuntu 20
python 3.8
chrome 91.0.4472.114
selenium 3.141.0
Update:
I found the input field below with the type of "file", but it's located at the bottom of the page. (not within the expected modal)
Passing the path to this element was successful (no selenium errors), but the upload process still failed.
<label tabindex="-1" style="visibility: hidden; position: absolute;
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px;
padding: 0px;">upload<input type="file" ngf-select=""
ng-model="model" ng-show="!model"></label>
"upload"
<input type="file" ngf-select="" ng-model="model" ng-show="!model">
<label tabindex="-1" style="visibility: hidden; position: absolute;
overflow: hidden; width: 0px; height: 0px; border: none; margin: 0px;
padding: 0px;">upload
<input type="file" ngf-select="" ng-model="model" ng-show="!model">
</label>
It turns out there was an element with type="file in a different section of the page. Accessing the correct element and using send_keys with the file path worked perfectly. The original text box in question was populated with the file name and the file upload occurred properly.
Thank you for everyone's input, especially #YaDavMaNish with the syntax that ultimately got this working.
Using python and selenium to select an option in a combobox drop down ng select. I want to select the 'MALE' option in a dropdown select. I am trying to use XPath.
The code I use:
driver.find_element_by_id("sex_0").click()
driver.find_element_by_xpath("//*[contains(text(), 'MALE')]").click()
Copy and pasted the HTML:
Please Select OptionFEMALEMALE
Inspect element of the HTML:
<ng-select _ngcontent-uau-c14="" bindlabel="cdDescr" bindvalue="cd" class="custom ng-select ng-select-single ng-select-searchable ng-untouched ng-pristine ng-valid ng-select-opened ng-select-bottom" placeholder="Please Select Option" role="listbox" title="Please Select Option" id="sex_0">
<div class="ng-select-container">
<div class="ng-value-container"><div class="ng-placeholder">Please Select Option</div><!----><!---->
<div class="ng-input" style="top: 0px;"><input role="combobox" type="text" autocomplete="ac08684b8af8" autocorrect="off" autocapitalize="off" aria-expanded="true" style="position: relative; top: 0px; left: -10px; padding-left: 10px; border: none !important; height: 45px; width: 468px;" aria-owns="ac08684b8af8" aria-activedescendant="ac08684b8af8-0"></div></div><!----><!---->
<span class="ng-arrow-wrapper"><span class="ng-arrow"></span></span></div><!---->
<ng-dropdown-panel class="ng-dropdown-panel ng-select-bottom" id="ac08684b8af8" style="opacity: 1;"><!---->
<div class="ng-dropdown-panel-items scroll-host"><div></div>
<div><!----><!---->
<div class="ng-option ng-option-marked" role="option" aria-selected="false" id="ac08684b8af8-0"><!----><!----><span class="ng-option-label">FEMALE</span></div>
<div class="ng-option" role="option" aria-selected="false" id="ac08684b8af8-1"><!----><!----><span class="ng-option-label">MALE</span></div>
<!----><!----><!----><!----></div></div><!----></ng-dropdown-panel></ng-select>
The problem:
It will select FEMALE instead of MALE because the XPath text "FEMALE" contains the text "MALE". I assume that the 'id="ac08684b8af8"' is randomly generated with each use, which means I can't use Selenium find element by id. I tried select using selenium but I get the error: "element of type ng select not select". Hence I used XPath. The "ng-option-marked" is just a feature when the cursor hovers above the dropdown selection.
How should I solve this problem?
Answer is in the comments by KunduK.
driver.find_element_by_xpath("//*[text()='MALE']").click()
I am trying to switch to frame but Selenium can't locate the element.
Here is HTML code which I get with Selenium before locating:
<div class="jqmPopOverlay" style="height: 100%; width: 100%; position: fixed; left: 0px; top: 0px; z-index: 2999; opacity: 0.7;"></div><div class="login login-main jqmID1" id="loginForm" style="z-index: 3000; top: 0px; left: 319.5px; display: block;">
<div class="titlebar">
<a class="close" href="#" tabindex="7">✕</a>
</div>
<div class="tooltipstered" id="loginFrame"><iframe frameborder="0" id="easyXDM_default127_provider" name="easyXDM_default127_provider" scrolling="no" style="height: 509.667px;" width="100%"></iframe></div>
</div>
<script async="" defer="" type="text/javascript">undefined</script><script async="" src="//www.googleadservices.com/pagead/conversion_async.js" type="text/javascript"></script><script async="" src="https://www.google-analytics.com/plugins/ua/ec.js" type="text/javascript"></script><script async="" src="https://www.google-analytics.com/analytics.js" type="text/javascript"></script><script async="" src="//www.googletagmanager.com/gtm.js?id=GTM-4DBM"></script><script type="text/javascript">
Here is Python code:
browser = webdriver.Chrome('chromedriver.exe')
browser.get(url)
frame = browser.find_element_by_id("easyXDM_default6255_provider")
browser.switch_to_frame(frame)
Here is the error:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"easyXDM_default6255_provider"}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
As you can see there is the element in HTML, but it can't be located.
What am I doing wrong?
Try this:
browser = webdriver.Chrome('chromedriver.exe')
browser.get(url)
WebDriverWait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//*[#id = 'loginFrame']/iframe")))
Note: you have to add some imports:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
Firstly, your frame probably has generic id and name. That's why I have proposed another selector. Secondly I have added WebDriverWait, which waits at least 10 seconds until frame will be available and only then switches to it.
PS: when you are done with content inside iframe, don't forget to switch to default content like this:
browser.switch_to.default_content()
otherwise you will be not able to interact with the whole DOM.