I try to click on a certaion option using the code:
countries_dropdown = self.browser.find_element_by_class_name('countryBR')
dropdown = countries_dropdown.find_element_by_id('ControlGroupContact_ContactInputView_DropDownListCountry')
self.browser.execute_script("arguments[0].classList.remove('jqTransformHidden');", dropdown)
country_dropdown = Select(countries_dropdown.find_element_by_id('ControlGroupContact_ContactInputView_DropDownListCountry'))
country_dropdown.select_by_value(payer_details.country_code.upper())
It seems like clicking but than when I try to click on the states the list is empty and the country dropdown seems open
Related
I am new to web scrapping. I am trying to scrape a website (for getting flight prices) using Python Selenium which has some drop down menu for fields like departure city, arrival city. The first option listen should be accessed and used.
Lets say that the field departure city is button, on click of that button, a new html page will be loaded with input box and a list set is available with every list element consisting of a button.
While debugging I found that, once my keyword is entered the options loading screen appears but options are not getting loaded even after increasing the sleep time (I have attached the image for the same).
image with error
Manually there are no issues with the drop down menu. As soon as I enter my departure city, options will be loaded and I choose the respective location.
I also tried to use actionchains. Unfortunately there is no luck. I am attaching my code below. Any help is appreciated.
#Manually trying to access the first element:**
#Accessing Input Field:**
fly_from = browser.find_element("xpath", "//button[contains(., 'Departing')]").click()
element = WebDriverWait(browser,10).until(ec.presence_of_element_located((By.ID,"location")))
#Sending the keyword:**
element.send_keys("Los Angeles")
#Selecting the first element:**
first_elem = browser.find_element("xpath", "//div[#class='classname default-padding']//div//ul//li[0]]//button")
Using Action Chains:
fly_from = browser.find_element("xpath", "//button[contains(., 'Departing')]").click()
time.sleep(10)
element = WebDriverWait(browser, 10).until(ec.presence_of_element_located((By.ID, "location")))
element.send_keys("Los Angeles")
time.sleep(3)
list_elem = browser.find_element("xpath", "//div[#class='class name default-padding']//div//ul//li[0]]//button")
size=element.size
action = ActionChains(browser)
action.move_to_element_with_offset(to_element=list_elem,xoffset =0.5*size['width'], yoffset=70).click().perform()
action.click(on_element = list_elem)
action.perform()
[![***
***]2][1]I'm working with selenium ide and I want to click on the button that is highlighted in the calendar that shows today
I have found an order in Selenium that can return the date of the day to me, but I want the date in the Persian solar calendar.
var d = new Date();
var m = ((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):
(d.getMonth()+1);
return d.getFullYear()+"-"+m+"-"+d.getDate();
I want to know if it is possible to click on a button highlighted with selenium ide
First, you can always click on elements by the text inside them using Xpath:
String xpathVal = "*//[contains(text()," + "'TEXT')]";
WebElement myElement = driver.findElementByXpath(xpathVal);
myElement.click();
Also, you can click on the dropdown (select) and do this:
Select select = (Select)driver.findElement(By.id
("ID of select element"));
select.selectByValue("optionText");
// or
select.selectByIndex(2);
I'm trying to select an element from a dropdown but getting an error.
Here is the HTML:
<select id="childContextDDL" data-filter="contains" data-role="dropdownlist" data-template="dcf-context-picker" data-value-field="Value" data-text-field="DisplayText" data-bind="events: { change: childContextListChange }, source: childContextList.ChildContextList" style="display: none;">
<option value="1">NATION</option>
<option value="12">ATLANTIC</option>
<option value="16">CHARLOTTE, NC</option>
And this is the code that I'm trying to run:
mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')
I'm getting this error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
What's the possible reason for getting this error? I'm very new to Selenium.
I also want to click on that element after selecting it.
The problem was that the style within the html was set to none. So I had to first change that style to block to make it visible and then proceed with the clicking operation.
Here's the code that worked:
driver.execute_script("document.getElementById('childContextDDL').style.display = 'block';")
mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')
randomClick = driver.find_element_by_id('dcf-user-info')
randomClick.click()
I guess the mySelect element (the dropdown menu) is not visible.
So please try the following:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
mySelect = Select(driver.find_element_by_id("childContextDDL"))
actions.move_to_element(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')
If the above doesn't work (I can't see the actual site you are working on), the following can work instead in the element has to be tapped to become enabled
action = TouchActions(driver)
action.tap(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')
If it says it is not currently visible, you should try pausing the code with one of this options:
time.sleep(1) #This states to your code to stop for 1 second and the continue with the work.
WebDriverWait(driver, 10).until(EC.element_to_be_visible(BY.value, "12")) # tells the driver to wait a maximum of ten seconds until the value "12" is visible for the driver.
I have a problem scraping data from the following site: https://arcc.sdcounty.ca.gov/Pages/Assessors-Roll-Tax.aspx.
I have to do these steps in order:
Select a drop down option "Street Address'
Enter a street address into a text field (ie 43 Hadar Dr)
Click the 'Submit' button.
After clicking submit, I should be directed to a page that has the APN number for a given address.
The problem:
I am able to do the above steps. However, when I select a drop down option and input address in the textbox, it fails as the textbox input address for some reason is cleared before clicking 'submit' ONLY when I have selected a drop down option.
I have tried using Selenium's Expected Conditions to trigger the input in the text box after a drop down option has been selected, but did nothing. I am looking for any help on identifying the why there is this problem as well as any advice on solutions.
Thanks.Much appreciated.
My code:
driver = webdriver.Chrome()
driver.get('https://arcc.sdcounty.ca.gov/Pages/Assessors-Roll-Tax.aspx')
#Selects drop down option ('Street Address')
mySelect = Select(driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25 ea12_ctl00_ddlSearch"))
my=mySelect.select_by_value('0')
wait = WebDriverWait(driver,300)
#Enter address in text box to left of drop down
driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ct l00_txtSearch").send_keys("11493 hadar dr")
#Click 'Submit' button to return API numbers associated with address
driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ctl00_btnSearch").click()
driver.quit()
Just changed a few things in your code to make it work.
mySelect = Select(driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25 ea12_ctl00_ddlSearch"))
To find_element_by_name(...):
mySelect = Select(driver.find_element_by_name("ctl00$ctl43$g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12$ctl00$ddlSearch"))
And
my=mySelect.select_by_value('0')
To select_by_visible_text('...'):
my = mySelect.select_by_visible_text("Street Address")
And
driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ct l00_txtSearch").send_keys("11493 hadar dr")
To find_element_by_xpath(...), since I usually get better results when finding elements by xpath.
driver.find_element_by_xpath('//*[#id="ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ctl00_txtSearch"]').send_keys("11493 hadar dr")
This is how it all looks like:
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
driver.get('https://arcc.sdcounty.ca.gov/Pages/Assessors-Roll-Tax.aspx')
#Selects drop down option ('Street Address')
mySelect = Select(driver.find_element_by_name("ctl00$ctl43$g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12$ctl00$ddlSearch"))
my = mySelect.select_by_visible_text("Street Address")
wait = WebDriverWait(driver,300)
#Enter address in text box to left of drop down
driver.find_element_by_xpath('//*[#id="ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ctl00_txtSearch"]').send_keys("11493 hadar dr")
#Click 'Submit' button to return API numbers associated with address
driver.find_element_by_id("ctl00_ctl43_g_d30f33ca_a5a7_4f69_bb21_cd4abc25ea12_ctl00_btnSearch").click()
driver.quit()
Not sure if this is your situation. But one thing that jumped out from your question is the text box input... Often, when filling in a website text box, even though the text is clearly visible, the text is not actually read by the text-box method until after the focus (cursor) is clicked or tabbed out and away from the text box.
Tabbing the text cursor out of the text entry box first, before 'clicking submit', will often solve this issue.
I need to do the following:
1) Right click on a element
2) Context menu is displayed
3) On moving
to a specific menu (move_to_element) in context menu - pops up
another menu say MenuX
4) Need to click on MenuX
I am able to do steps 1 to 3 but not 4.
When I checked is_displayed for MenuX it returns False
When I try driver.find_element_by_xpath("html/body/div[5]/span[2]")
it works (I do not want to hardcode).
But not with id of menu.
Also tried but no luck
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
I also tried driver.find_element_by_css_selector("div#contextMenu_Div #menuX") and it didn't work.
MenuX is not link but a span element.
Try to use below code in order to click on the sub menu item after right clicking:
WebElement element = driver.findElement("Find the element on which right click needs to be performed"));
Actions actions = new Actions(driver).contextClick(element);
WebElement mainMenu = driver.findElement(By.linkText("menulink"));
actions.moveToElement(mainMenu);
WebElement menuX = driver.findElement(By.cssSelector("subLinklocator"));
actions.moveToElement(menuX);
actions.click().build().perform();
Hope this helps
Can you try this..
Actions actions = new Actions(driver);
actions.contextClick(mainelement);
actions.moveToElement(menuelement);
actions.perform();
//at this point ur MenuX shd be visisble.
driver.findElement("locator for ur MenuX").click();