Select a value from a ajax drop down - python

I am trying to mimic selecting a value from an ajax dropdown value using selenium and python. I am not sure how to approach this.
This is how the text box works - I enter in the value, it searches for it and appears at the bottom of the text box as an ajax drop down. How can I select that using selenium and python?
Here is the highlighted html code for that field

Related

how can i select value from react dropdown using selenium python?

I am doing website testing in selenium python. I am not able to select a value from the dropdown. Can anyone help me to do that?
This is my website source code.
when expanding dropdown it does not show value in the DOM so how can I select state Alaska?
As per the attachment, text box accepts input and filters dropdown list based on our input..To handle these cases:
You can use Actions class to handle this.
Actions(driver).click(element).sendKeys("Alaska").sendKeys(Keys.ENTER).perform();
Here, we are communicating with search box cum dropdown and entering "Alaska" in it. Once it entered, it filters the results and display only Alaska in the dropdown.
Later Keys.ENTER just performs ENTER operation which will select the first record in the dropdown list.
Use text to identify WebElement. First click on dropdown and write generic xpath like '//*[text()='Alaska']'. This solution may or may not work. But solution 1 is recommendable..

Python selecting with (java-enabled?) dropdown selection

am new to coding and have been trying to select a dropdown box to select underlying options. Have been able to interact with other drop-down on this page, though this particular one seems different as I've been unable to access/interact with it
I've included a snapshot of the webpage's drop-down box, source codes for the specific drop-down box, and codes that I've already tried and had errors with.
Would appreciate any help/pointers. Am a complete newb to coding (python or HTML!), but know a little about Excel VBA.
website: https://www.firstsentierinvestors.com/sg/en/retail/performance/price-and-performance.html
Tried to paste a picture though it seems I'm too new to do so directly. I'm trying to interact with the "Select Fund" drop-down box on the page. Have tried the following codes:
browser.find_element_by_id('strategy').send_keys(fund_strat) #works fine
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
browser.find_element_by_xpath('THE BELOW XPATHS').click()
//*[#id="price-performance-form"]/div[3]
//*[#id="price-performance-form"]/div[3]/div
//*[#id="price-performance-form"]/div[3]/div/a
//*[#id="price-performance-form"]/div[3]/div/a/span
//*[#id="share-class"]
//*[#id="share-class"]/option[1]
Also tried using CSS selector
browser.find_element_by_css_selector('a.option-selected').click()
browser.find_element_by_css_selector('a.option-selected').send_keys('NAME OF FUNDS ETC')
Image describing problem
If the below line works fine for you then,
browser.find_element_by_xpath('//*[#id="share-class"]').click()
#this line directly above does not work, including variants below:
You need to wait for the element which is visible on the DOM.
i.e.,css = <div class="custom-select custom-select-open">
These days most of the web apps are using AJAX techniques.
So you need to add a wait duration (till the element gets visible on the page or get loaded on the DOM).
So, Try using Selenium Waits(put below code):
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XX, 'element')))
XX = CSS, XPATH, ID, etc.
Now, If you want to write on the selected text box then just try to send keys on input element.
browser.find_element_by_css_selector('.editable-select input')
for much better selector use parent elements to locate the exact element.
CSS = 'div[class$="custom-select custom-select-open"] .editable-select input'
If you want to select dropdown options and you know the Values. Try using below CSS.
browser.find_element_by_css_selector('select option[value$="Your Value"]')
or
If you don't know the values then please attach whole DOM feed after typing into the text box. I'll try to help you out with the Dropdown selection of item.
Else, there is few more steps are there that you need to workout. Get all elements using inside text.
Note: You can approach the text search of an element using XPATH. Example : xpath = "//*[contains(text(),'your text')]"

in robot framewerk text edit using selenium library

This is an issue I'm facing while automating my test case via robot framework, I'm trying to click on the Action column of 3rd row in the below table (screenshot below)
The Xpath I'm using is as below
Click element xpath=.//table[id="mylogiusers"]/tbody/tr[3]/td[37]
${table_cell} Get Table Cell xpath=//table[contains(#id,'mylogiusers')]
Click Link ${table_cell}
Note - there are multiple hidden columns in the table, so though the Action column appears to be 10th but in the html table it's number 37, so added td[37] in above xpath.
This is a bootstrap table, please let me know where I'm going wrong, tried multiple options in xpath but none seems to be working here.

Python Selenium , Click a checkbox

I am trying to create an add to car bot which finds the item and selects the size and fills out the user billing and card information. I am currently stuck on the checkboxes of the site. I've tried to use the XPath of the checkbox and it gives me an error or it won't execute.
The website I am using is as below:
https://www.supremenewyork.com/checkout
Below is a picture of the checkout page with the checkbox
Here is the html elements used for the code
Below is my code that I used to get the program to find the checkbox element and use a .click() to select the box.
Checkboxes = browser.find_element_by_xpath('//*[#id="cart-cc"]/fieldset/p[2]/label/')
Terms = ActionChains(browser).move_to_element(Checkboxes).click()
Terms.perform()
use below code:
Webelement element = browser.find_element_by_xpath('//label[./div[#class="icheckbox_minimal"]/input[type="checkbox"]]/div/input');
element.click();

manipulating multiple select boxes on a website via python not triggering POST request

I'm trying to programmatically manipulate an internal website via python. It's actually working for the most part, but I'm stuck trying to trigger a POST request after the value of each box changes. I can see in the Chrome debugger that a POST request is made after I click on a value in one of the select boxes.
For example, there are three select boxes and each one is dependent on the last.
When a value is selected in select box A, select box B is populated via AJAX.
When a value is selected in select box B, select box C is populated via AJAX.
The items in select box A are statically loaded when the page is loaded. I can iterate through those with no problems.
import win32com.client
ie = win32com.client.DispatchEx("InternetExplorer.Application")
ie.Navigate("...")
# stuff to see if the page loaded...
boxAObj = doc.getElementById("selectBoxA")
for i in range(1,boxAObj):
# I've tried this multiple ways - none have triggered the request
boxAObj.options.selectedIndex = i
boxBObj = doc.getElementById("selectBoxB")
print boxBObj.length
The print statement always prints 1. There was a default value in the select box "Select...", so that's why the length is 1.
Here are some images of the site to show the behavior. The first one is after a fresh page load with nothing selected either by the mouse or via javascript.
In this picture, I programmatically selected an item in select box A using javascript, but nothing was loaded in select box B:
In this picture, I clicked the same value in select box A and you can see that select box B populated as expected:
The last piece of information is that the select boxes have onchange events assigned to them. Is that the key to this problem?
Edit: I just found a post that shows obj.onchange() from javascript should do the trick, which works in the browser, but not from python. Should I try to eval the function in python? I've tried a few things, but nothing has worked yet. See below:

Categories