Element is not clicking on click in python selenium webdriver in Odoo - python

there is a list field which I have sticked with an image
Here after clicking on the list , I have to select first option that is Cash(EUR)
I have written a code in python by xpath that is ,
browser.find_element_by_xpath("//Select[#name='journal_id']/option[normalize-space(text())='Cash (EUR)']").click()
from this code , it will let me select that perticular element but not able to click on that element instead of writing click()
So , whats the exact code ? or give me specific code so that I will be able to click on that element

You should use here selenium select command, instead of click. as it is drop down not clickable element.

It may be done by this that first I focus on that list box on which I have to select cash option then I will search an element by keyboard by send_key method & in which I will enter work for ex. Cash , then this process will run automatically like we select an element just like entering their name by a keyboard
a=browser.find_element_by_xpath("html/body/div[6]/div/div/div[2]/div/div/div/div/div/div[2]/div/div[4]/div/div/table[1]/tbody/tr/td[1]/table/tbody/tr[5]/td[2]/span/select")
a.send_keys("Cash (EUR)")
It works :)
Here it will automatically select cash option by not going options view

Related

Selenium Python Am I selecting a drop down item the best way?

I'm working on my first-ever Selenium Python project and am baby stepping through it. I have an inconsistent issue and want to see if there's a better way to code it.
I need to select "Active" from a drop-down menu. I'm selecting the drop down input element and clicking on it. This will open a child element of the input with the list items in it. Here's where the problem lies...sometimes the drop down element stays open and I can select "Active" and everything works great. Sometimes, however, the drop down element opens and closes immediately before I can pick "Active". I'm currently trying to sleep for 3 seconds after clicking on the input element, hoping that will solve the issue. It seemed to for a little while, but now then it will revert back to closing immediately.
So is there a better way to open this drop down box and select active?
#select the status drop down box and click to open it, wait 3 seconds to make sure it loads
#and select the 'A'ctive list item and click to select it
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "input-w_112"))).click()
time.sleep(3)
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "w_113"))).find_element(By.XPATH, '//*[#combovalue="A"]').click()
Sometimes the list items box will stay open, sometimes it closes immediately.
You can do this task with executing a JS script from Selenium WebDriver.
Select the drop-down menu you need.
Select an option by its index.
Code
JS_script = """
var menu = document.getElementById("menu");
menu.selectedIndex = 0;
"""
driver.execute_script(JS_script)

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..

select a dropdown box using Selenium python

I am having trouble selecting a particular dropdown element via Selenium. The website is password protected so I have shared a snapshot of it. The attached snapshot shows what is visible when I right-click on the element and choose 'Inspect'. I am selecting XPATH which I have pasted in the pictures address bar to show what it is. Then I use the following line in my script to click it but it says element is not visible.
WebDriverWait(Chromedriver, 240).until(EC.presence_of_element_located((By.XPATH, '//*[#id="dateRangeType"]'))).click()
I have noticed that this element does not have a class to it. If that is the reason it is not working, how would I select an element with id, name but no class?
I found the answer myself, the element was supposed to be clicked from the top of its hierarchy:
WebDriverWait(Chromedriver, 240).until(EC.presence_of_element_located((By.XPATH,'//*[#id="individual_member_det"]/div/div/div[6]/select'))).click()

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();

python selenium: element not visible in [weird] dropdown to be clicked

There are two dropdown element code: one is standard option-select and the other is made of div, ul, li elements.
And somehow both are used to select a dropdown element via javascript...
Problem is selenium is not able to click the element and throws not visible exception.....
See the dropdown box here: [Its below "Top 5" tab]
http://www.oddsbox.com/baseball/mlb/record/section.odd
Following solutions don't help either:
Python Selenium: Find object attributes using xpath
selecting element in python selenium
Selenium nested li div menu select() or click() python
how to select custom dropdown list element from selenium
It would be nice if you'd post your code, so we can see a bit clearer what's happening.
Also admitted, I did not check all of your links to see everything that doesn't work. However my guess is this:
If you get an ElementNotVisible exception, then you should probably make your element visible before selecting it.
In this case I'd forget about the selecting commands and all and just :
- click on the element to open and reveal the menu and then
- click on the desired element inside that list.
Looks something like :
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/button").click()
driver.find_element_by_xpath(".//*[#id='ctmSelectBox4_wrap']/div/ol/li[6]/label/span").click()
I personally detest these ugly xpaths (especially for maintainability), and probably would change that somehow, but that's not the scope of this question.
Hope that helps!

Categories