I am trying to acces and change the date on the following website with Python/Selenium:
http://www.b3.com.br/en_us/market-data-and-indices/data-services/market-data/historical-data/derivatives/trading-session-settlements/
When trying to click on the calender i get the following error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div[1]/div[1]/div/form/div/div[1]
I guess i need to active some js-code but i am having trouble to locate the specific js-code. Does anyone have any suggestion to how i can activate the content on the webpage?
I have tried using the following code:
driver.get('http://www.b3.com.br/en_us/market-data-and-indices/data-services/market-data/historical-data/derivatives/trading-session-settlements/')
time.sleep(5)
driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/form/div').click()
driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/form/div/div[1]').click()
driver.find_element_by_xpath('//*[#id="dData1"]').click()
driver.find_element_by_xpath('//*[#id="dData1"]').clear()
driver.find_element_by_xpath('//*[#id="dData1"]').send_keys('04/08/2020')
I get that the code already fails at line 2, but i dont understand why as i copied the Xpath like i always do, when using selenium on a webpage.
Thanks in advance for the help!
iframe is present on your web page, switch control on it before performing send key. Refer below solution :
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("http://www.b3.com.br/en_us/market-data-and-indices/data-services/market-data/historical-data/derivatives/trading-session-settlements/")
# driver.find_element_by_tag_name('body').send_keys("Keys.ESCAPE")
iframe=driver.find_element_by_id("bvmf_iframe")
driver.switch_to.frame(iframe)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "input#dData1.datepicker.hasdatepicker"))).clear()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "input#dData1.datepicker.hasdatepicker"))).send_keys('02/01/2021')
Note : Add below imports to your solution :
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
Output:
Related
I have a question about Selenium.
My idea:
My idea is to make a Python script that logs in to this website.
Selenium sends the username and password to the HTML input field and submits it.
Problem:
My code keeps saying:
Message: no such element: Unable to locate element:
I have tried this code with google.com for example and that works.
Why is this not working with this login page?
Can anybody help me please?
My Python code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
login_URL = ""
driver = webdriver.Chrome()
driver.get(login_URL)
time.sleep(5)
inputElement = driver.find_element_by_name('uname')
inputElement.send_keys(username)
time.sleep(20)
driver.close()
i don't know how it works in pyton, im use js
but try to use xpath
driver.find_element_by_xpath('your xpath') [maybe use 1 more click) ('xpath element').click() - element is active.
and after use send keys
******.send_keys('username')
driver.switchTo().frame(driver.findElement(By.xpath('xpath frame'))) - in js
As already explained, the element is in an iframe. Need to switch to frame to interact with the element.
It would be better apply Explicit waits.
# Imports required:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.get("https://nl.infothek-sptk.com/isps/infothek/?1043")
wait = WebDriverWait(driver,30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"body_frame")))
wait.until(EC.element_to_be_clickable((By.NAME,"uname"))).send_keys("username#mail.com")
# Code to enter other fields.
# Switch back to default to interact with elements outside the iframe.
driver.switch_to.default_content()
I am trying to extract the user reviews from google app using selenium webdriver. I loaded all reviews on the web-browser. Now I want to change the 'Most relevant' option of review page to 'Newest' option as shown in the picture.
Here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
baseurl = 'https://play.google.com/store/apps/details?id=com.mapmyrun.android2&showAllReviews=true'
driver.get(baseurl)
driver.find_element_by_xpath("//div[#class='OA0qNb ncFHed']//div[#class='MocG8c UFSXYb LMgvRb KKjvXb']//span[#class='vRMGwf oJeWuf']").click()
When I ran the code, it throws following error:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[#class='OA0qNb ncFHed']//div[#class='MocG8c UFSXYb LMgvRb KKjvXb']//span[#class='vRMGwf oJeWuf']"}
To click on google review options as Newest Induce WebDriverWait() and wait for element_to_be_clickable() and following xpath option.
driver.get("https://play.google.com/store/apps/details?id=com.mapmyrun.android2&showAllReviews=true")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[./span[text()='Most relevant']]"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#role='option'][./span[text()='Newest']]"))).click()
Browser snapshot:
If you want to simply click the div and click newest. Your class is dynamic and will change it's better to get an indentification that won't change.
driver.get("https://play.google.com/store/apps/details?id=com.mapmyrun.android2&showAllReviews=true")
driver.find_element_by_xpath("//span[text()='Most relevant']/parent::div").click()
time.sleep(3)
driver.find_elements_by_xpath("//span[text()='Newest']")[1].click()
HTMLI want to select a textbox using XPath or any other locator, but I am unable to do so. The code is working fine for one part of the page, while it is not working using any locator for the other half of the page. I am not sure if my code is wrong or if something else is the problem.
I have attached the HTML part.
Here is my code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get('Website')
driver.implicitly_wait(50)
driver.find_element_by_xpath('//*[#id="j_username"]').send_keys("Username")
driver.find_element_by_xpath('//*[#id="j_password"]').send_keys("Password")
driver.find_element_by_xpath('//*[#id="b_submit"]').click()
driver.find_element_by_xpath('//*[#id="15301"]/div[1]/a/span').click()
driver.find_element_by_xpath('//*[#id="22261"]/a').click()
driver.find_element_by_xpath('//*[#id="22323"]/a').click()
driver.implicitly_wait(50)
driver.find_element_by_xpath('//*[#id="filterRow"]').clear()
The last line is where I am getting the following error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="filterRow"]"}
Page may have not finished rendering when you try to find the element. So it will give NoSuchElementException
Try the following method
elem = driver.find_element_by_xpath('//*[#id="filterRow"]')
if len(elem) > 0
elem[0].clear()
Hope this will help you
You can wait till the elements loads using wait -
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
Filter_Row = wait.until(EC.visibility_of_element_located((By.XPATH, '//*[#id="filterRow"]')))
Filter_Row.clear()
Try the above code and see what happens.
Try below solution
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[#id='filterRow']"))).clear()
Note: add below imports to your solution :
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
As in one of comments, you mentioned upon clicking tab a new page is opening. Can you please check if its opening in a new frame. Is so please switch to frame first where your element is using below statement:
driver.switch_to.frame(driver.find_element_by_name(name))
To navigate back to original frame you can use:
driver.switch_to.default_content()
using 'find_element_by_css_selector'
driver.find_element_by_css_selector("input")
I need CFBundleversion of my apps so i've tried scrapy iTunes Connect website but i can't get element.
I tried:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://appstoreconnect.apple.com/login")
elem = driver.find_element_by_xpath("//input[#id='account_name_text_field']")
I am receiving the following error:
elenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element: //input[#id='account_name_text_field']
i think the site is different structure...
what should i do?
Nothing wrong with you locator :
driver.find_element_by_xpath("//input[#id='account_name_text_field']")
It inside iframe, you need switch first, use frame_to_be_available_and_switch_to_it and visibility_of_element_located, like this:
driver.get('https://appstoreconnect.apple.com/login')
WebDriverWait(driver, 30).until(expected_conditions.frame_to_be_available_and_switch_to_it((By.ID, "aid-auth-widget-iFrame")))
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located((By.XPATH, "//input[#id='account_name_text_field']")))
elem = driver.find_element_by_xpath("//input[#id='account_name_text_field']")
elem.send_keys("userName")
Following import:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
the link is "https://www.psacard.com/smrpriceguide/baseball-card-values/1909-11-t206-white-border/1055/".
My question is: How I will get the index of the particular record of which Description contains "Carolina". Also how can I click the hyperlink(Shop) against that row. Please provide solution with python and selenium only.
With selenium, I usually use xpath searches. I suggest googling xpath, but here's a quick example for your case:
Find a div element who's text is exactly Carolina Brights:
//div[text()="Carolina Brights"]
in selenium:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
browser = webdriver.PhantomJS()
browser.implicitly_wait(10)
my_xpath = '//div[text()="Carolina Brights"]]'
my_div = WebDriverWait(browser, 10).until(
EC.visibility_of_element_located((By.XPATH, my_xpath))
)
my_div.click()
Obviously that particular div has no onClick so no point clicking it, but you get the idea ...