I want to enter the "Symbol" name and select tab "NSE" from the filter. Once that is done, click on table view button using Selenium. But I cannot find any of these nodes using Debugger.
(https://i.stack.imgur.com/uOrQc.png)
The original class "chart-frame" is found.
driver.find_element(By.ID, "chart-iframe")
I get "No such element" for any of the below commands. I cannot find any information on this CQ tags online.
driver.find_element(By.CLASS_NAME, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-DT.tableview-ui")
driver.find_elements(By.XPATH, '//button')
Firstly, you need to switch into that iframe to scrape whatever you wanna scrape. You can use following code snippet for it:
iframe = driver.find_element(By.XPATH, "//iframe[#name='TheIframeName']")
driver.switch_to.frame(iframe)
You can use driver.switch_to.default_content() to switch back to default content.
Related
I'm new to using Selenium with Python. I'm trying to click on this sign-in button on glassdoor: Glassdoor Sign-in Button
Actual: Using both the XPATH and the classname "LockedHomeHeaderStyles__signInButton", I keep getting the "ElementNotInteractableException" thrown.
Expected: I should be able to select the element and click it.
When I open the site and try to manually click the button myself, I am able to do this. Am I doing something wrong in my code?
def sign_in():
sign_in_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "LockedHomeHeaderStyles__signInButton"))
)
sign_in_element.click();
There are two button element with "Sign In" text. You need second one. Try using the below xpath-
//button[text()="Sign In" and not(contains(#class,"d-flex"))]
I'm trying to locate a element, but I can't click on it. The id is ("save-all-conditionally"), but it's not working if I click on it. I tried css.selector, xpath and all other things, but nothing is working!
There are 2 frames, frame inside frame.
You would need to switch to parent frame then child frame.
here is the working code :
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://www.gmx.net/consent-management/")
driver.implicitly_wait(10)
firstFrame = driver.find_element_by_xpath("//iframe[#class='permission-core-iframe']")
driver.switch_to.frame(firstFrame)
driver.switch_to.frame(0)
driver.find_element_by_xpath("//button[#id='save-all-conditionally']").click()
Try this code, see if it works:
ele = driver.find_element_by_xpath("//*[#id='save-all-conditionally']")
ele.click()
Not tested yet:
iframe = driver.find_elements_by_tag_name('iframe')
if len(iframe) == 1:
driver.switch_to.frame(iframe[0])
button = driver.find_element_by_id('save-all-conditionally')
if button:
button.click()
Since the iframe has no id get it by tag name, it should be one iframe use switch_to.frame to switch to the iframe content and get the button to click on it
I'm trying to crawl a website for sports statistics, and realised all of the important data is inside an iframe. I use driver.switch_to.frame() to switch to the iframe and that doesn't throw any errors.
frame1 = '//iframe[#src="reallylongsource"]'
driver.switch_to.frame(driver.find_element_by_xpath(frame1))
But then when I try to access the information inside the iframe,
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .//div[#class="classname"]
is raised. I can see that the element is there in the HTML but I can't find it with selenium. I've tried locating it with CSS selector as well with no success.
I'm quite sure it's the correct iframe as well. I've tried finding it both with the xpath and by tag name and they were the same iframe.
When I print
print(driver.find_element_by_xpath(frame1).text)
I only get blank space
I've been butting my head against the wall for quite a while now and can't figure it out!
It seems like I'm able to switch to the correct iframe, but selenium can't find any information within it.
try use like this:
driver = webdriver.Chrome()
driver.get(URL)
driver.implicitly_wait(5)
driver.switch_to.frame(driver.find_element(By.TAG_NAME, 'iframe'))
element = driver.find_element(By.XPATH, '//div[#class="classname"]')
driver.quit()
if it's the same what you're doing in your code, please provide more info to take a look of the page
try this, it will move to the first game of first type game and get all of the scores and prints it:
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://campobet.se/en/sport/prelive?sportids=66')
time.sleep(5)
driver.switch_to.frame(
driver.find_element_by_xpath("//iframe[contains(#src, 'https://sb1client-altenar.biahosted.com')]"))
time.sleep(1)
game_types = driver.find_elements_by_xpath("//div[#name='leagues-selector']")
time.sleep(1)
game_types[0].click()
time.sleep(1)
games = driver.find_elements_by_xpath(
"//div[#class='_asb_simple-button _asb_simple-button-pointer _asb_leagues-selector-item ']")
games[0].click()
time.sleep(1)
scores = driver.find_elements_by_xpath("//div[#class='asb-flex-cc asb-unshrink _asb_price-block-content-price ']/span")
time.sleep(1)
scores_values = [el.text for el in scores]
time.sleep(1)
print(scores_values)
driver.quit()
There is a form on this site and I am trying to get every option from it and click a search button with this code:
from selenium import webdriver
driver = webdriver.PhantomJS('c:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
driver.get('http://www.cobar.org/Find-A-Lawyer')
driver.implicitly_wait(20)
options = driver.find_element_by_xpath('//select[#id="FAL_FOP_field"]')
for option in options.find_elements_by_tag_name('option'):
if option.text != 'ALL':
option.click()
#click search button
driver.find_element_by_xpath('//button[#class="btn btn-primary btn-main"]').click()
lawyer = driver.find_element_by_xpath('//table[#id="myTable"]/tbody/tr/td[0]')
print(lawyer)
However I am getting:
selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":
"Unable to find element with xpath '//select[#id=\"FAL_FOP_field\"]'",
"request":{"headers":{"Accept":"application/json","Accept-Encoding":
"identity","Connection":"close","Content-Length":"115","Content-Type":
"application/json;charset=UTF-8","Host":"127.0.0.1:52809","User-Agent":"Python-urllib/2.7"}
,"httpVersion":"1.1","method":"POST","post":
"{\"using\": \"xpath\", \"sessionId\": \"e03be070-e353-11e6-83b5-5f7f74696cce\","
" \"value\": \"//select[#id=\\\"FAL_FOP_field\\\"]\"}","url":"/element",
"urlParsed":{"anchor":"","query":"","file":"element","directory":"/",
"path":"/element","relative":"/element","port":"","host":"","password":"","user":"",
"userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},
"chunks":["element"]},"urlOriginal":"/session/e03be070-e353-11e6-83b5-5f7f74696cce/element"}}
what should I do?
Error is because fields you are locating are inside iFrame.
So, first you need to switch to iframe and then locate your elements.
still, if didn't work, add time delay.
To locate iFrame :
WebElement iframelocator = driver.findElement(By.xpath("//iframe[#id='dnn_ctr2047_IFrame_htmIFrame']"));
Then Switch to iFrame
driver.switchTo().frame(iframelocator);
Add above two steps in your code before locating elements.
Note : Above written code is in java.
I tried find this URL page to do some selenium automation test, usually can get web element but some page is strange...i can not find the web element even using XPATH (use chrome browser can see the element, But can not do some action for this element..in fact...wrong message is "can not find the element)
looks like is asp.classic generate page....windows.onload() page
driver_path = os.path.join(os.getcwd(), "IEDriverServer.exe")
driver = webdriver.Ie(driver_path)
driver.get(mytestpage)
element = WebDriverWait(driver, 300).until(
EC.element_to_be_clickable((By.LINK_TEXT, "Hardware")))
element.click()
element = WebDriverWait(driver, 300).until(
EC.element_to_be_clickable((By.XPATH, "'//*[#id="testpage"]/table/tbody/tr/td[2]/table/tbody/tr[1]/td[2]/font/a[1]'")))
element.click()
Have you tried with selenium explicit wait? This might be because a page is getting loaded fully while you are performing selenium action on that page. Also, check response time for loading page.