After filling a form I am trying to click the following submit button:
<div class="tl_formbody_submit">
<div class="tl_submit_container">
<input type="submit" class="tl_submit" value="Einstellungen speichern" onclick="Backend.getScrollOffset()">
</div>
The code is:
browser.find_by_xpath('//input[#class="tl_submit"]').click()
The stacktrace says, that the element is not visible - but why?
Thanks!
# import options
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
# desired url link
URL = 'www.path.com'
#driver & settings
driver = webdriver.Chrome('PATH TO CHROMEDRIVER.EXE')
driver.get('URL')
driver.delete_all_cookies
#find element & click
driver.find_element_by_id("Einstellungen speichern").click()
if the stacktrace says element is not visible, if means it's not visible when you are trying to find it.
may be some action requires to make it visible (some ajax request) or may be you just need to wait a while before you click it.
you could use explicit wait as mentioned below.
submit_button = WebDriverWait(driver, 30).until(EC.visibility_of_any_elements_located((By.XPATH, "//input[#class='tl_submit']")))
submit_button.click()
One of the reason for the element to be 'not visible' is due to the error in assigning the xpath. Best way is to copy the xpath from the html (inspect element) and paste it. It works for most of the cases, try it.
You can check the link below, I had got a similar problem too, the possible solution can be here but for me the above-mentioned solution was fine.
How to fix "Element not interactable" Selenium error in Python?
Related
Im trying to automize some webpages and run into the following error:
I have passed the login screen, which gives no problems, but after being redirected to the next page, python gives the following error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
I have tried to fix it by introducing the driver.implicitly.wait, the time.sleep and the WebDriverWait(driver, time).until(EC.presence_of_element_located((By.ID, "myDynamicElement")) functions, but all the options do not seem to work.
I have shown the relevant HTML code below:
<input type="Text" class="urEdf2TxtEnbl" autocomplete="off" id="DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp" ct="I" name="DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp" st="" tp="STRING" value="502309" onchange="sapUrMapi_InputField_change('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);" onblur="sapUrMapi_InputField_Blur('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);" onkeydown="sapUrMapi_InputField_keydown('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);" onkeyup="sapUrMapi_InputField_KeyUp('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);" onfocus="sapUrMapi_InputField_focus('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);" onselectstart="sapUrMapi_InputField_onselectstart('DLG_VARIABLE_vsc_CommonVariablesList_VAR_5_VARINPUT_inp',event);">
The HTML code in the region around this is shown below:
<input type="Text" class="urEdf2TxtEnbl" autocomplete="off" id="DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp" ct="I" name="DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp" st="" tp="STRING" value="" onchange="sapUrMapi_InputField_change('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);" onblur="sapUrMapi_InputField_Blur('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);" onkeydown="sapUrMapi_InputField_keydown('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);" onkeyup="sapUrMapi_InputField_KeyUp('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);" onfocus="sapUrMapi_InputField_focus('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);" onselectstart="sapUrMapi_InputField_onselectstart('DLG_VARIABLE_vsc_CommonVariablesList_VAR_4_VARINPUT_inp',event);">
What I am trying to do is to change the value: value="502309". See below for the full code:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('xxxx')
login = driver.find_element_by_xpath('xxx')
login.send_keys('xxx')
passw = driver.find_element_by_xpath('xxx')
passw.send_keys('xxx')
button = driver.find_element_by_xpath('xxx')
button.click()
driver.maximize_window()
driver.implicitly_wait(120)
mat = driver.find_element_by_id('DLG_VARIABLE_vsc_CommonVariablesList_VAR_2_VARINPUT_inp')
driver.close()
Try to print the html using beautifulsoup so you can check if the element really exist. For your reference on how to use it, see link
I don't know if this will help but i had the same problem and solved it by this:
searchbox = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.XPATH, "your_xpath_here")
The above code shows that the webdriver will wait's for an element located in your page.
Issue with your code is not wait , but rather correct element locator. As far as I can see from limited HTML DOM you have provided, part of name and id of element you want to locate inside variable mat is changing. You can locate your element using below code ( Also i have included more sophisticated way to wait for element load).
mat = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.XPATH, "//input[starts-with(#id,'DLG_VARIABLE_vsc_CommonVariablesList_VAR')]")))
I have a problem navigating a website using selenium. This is my code:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://webtrader.binary.com/v2.2.8/main.html#')
resources = driver.find_element_by_id('ui-id-1')
resources.click()
However, I get the exception:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <ul id="ui-id-1" class="ui-menu ui-widget ui-widget-content ui-menu-icons"> could not be scrolled into view
I don't understand where I went wrong. I am trying to access 'Historical data' from the dropdown menu labeled "Resources". Could someone please help me access it. Maybe I got the id for Resources wrong. You could also check that out.
The element you want to click to open the dropdown is the previous sibling of the element resources
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.select import By
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 10)
driver.find_element_by_class_name('resources').click()
historical_data = wait.until(ec.visibility_of_element_located((By.ID, 'ui-id-4')))
There are many things happening here. First of all, your code is lacking a wait. Without it will always fail, as the page is dynamically loaded. Read about Waits.
Secondly, here resources = driver.find_element_by_id('ui-id-1') you are finding the element from the dropdown menu, and then you are trying to click it. But the dropdown menu is not opened. You should click on it, then wait for the option to appear, only then click on the 'Historical data'.
The question on the survey asks: What days of the week are you consistently available? I would like to check Sunday.
I am duplicating the code I see from an online video, however, I am receiving this error. Some people are suggesting that a pop-up may be blocking the program from working correctly but I do not see a pop up.
I have tried using chromedriver and geckodriver. The error is present in both.
The code to see if Sunday is selected works properly:
status=driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()
print(status)
output:
False
Here is my code:
from selenium import webdriver
driver=webdriver.Chrome(executable_path="my_webdriver_path"\\chromedriver.exe
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
What days of the week are you consistently available?
I would now like to check the Sunday box. Here is my code:
status=driver.find_element_by_id("RESULT_CheckBox-8_0").click()
print(status)
I would like the Sunday box checked but I am receiving this error:
selenium.common.exceptions.ElementClickInterceptedException: Message: Element <input id="RESULT_CheckBox-8_0" class="multiple_choice" name="RESULT_CheckBox-8" type="checkbox"> is not clickable at point (313,599) because another element <label> obscures it
I do not see another element that obscures the program. Does anyone have any suggestions? I am new to coding so any help would be greatly appreciated.
The problem you're having is related to the same values that are being used for different attributes in the label and input tags.
As you can see the 'for' attribute of the label has the same value as the 'id' attribute (wich doesn't allways have to be a unique value) of the eventhough you are using 'find_element_by_id'.
To fix this you could use a different locator like XPATH. You can get a xpath by right clicking on the element (when you are inspecting the code with f12) and than select [copy] - [xpath]
Here is some code that should work (note: I have placed the chromedriver.exe in the same location as the .py file it self):
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
status = driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()
if status:
pass
else:
driver.find_element_by_xpath("//*[#id='q15']/table/tbody/tr/td[1]/label").click()
Don't forget to eventually close the driver, otherwise it will stay in de background as a running procces.
You can do so by:
driver.close()
Hope this helps!
Try use ActionChains to click the element.
element = driver.find_element_by_id("RESULT_CheckBox-8_0")
ActionChains(driver).move_to_element(element).click(element).perform()
status = driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()
print(status)
Following import:
from selenium.webdriver import ActionChains
To click() on the checkbox with text as Sunday you can use the following Locator Strategy:
Using XPATH:
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(#for, 'RESULT_CheckBox-') and contains(., 'Sunday')]"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
I am trying to login to a website using python so that I can get some of their text from the website.
Here is my code. There always an error at the end of the code after the id and password code.
import os
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(executable_path=r"C:\chromedriver\chromedriver.exe")
driver.get('https://www.saramin.co.kr/zf_user/auth')
driver.implicitly_wait(3)
driver.find_element_by_name('id').send_keys('<<my_id>>')
driver.find_element_by_name('password').send_keys('<<my_password>>')
driver.find_element_by_xpath('//*[#id="frmNIDLogin"]/fieldset/input').click()
HTML source of the button:
Eventually I figured it out! Thanks for your answer though.
Here is the final code.
driver = webdriver.Chrome(executable_path="C:\chromedriver\chromedriver.exe")
browser = webdriver.Chrome('C:\chromedriver\chromedriver.exe')
driver.get('https://www.saramin.co.kr/zf_user/auth')
driver.implicitly_wait(3)
driver.find_element_by_name('id').send_keys('ID') driver.find_element_by_name('password').send_keys('PW')
driver.find_element_by_xpath( '//*[#class="btn-login"]' ).click()
The xpath is incorrect, it doesn't match anything in the page. Try
driver.find_element_by_xpath('//form[#id="login_frm"]//button[#class="btn-login"]').click()
or simply use submit() function on the <form>
form = driver.find_element_by_id('login_frm')
form.submit()
In the first case you were using 'id' ('//*[#id="frmNIDLogin"]) for click button, because 'id' changes every time page loads it was giving error. But in the second case when you used class ( '//*[#class="btn-login"]' ) it worked because it remains same every time page is loaded. Also as mentioned above the value of id in first case was wrong.
I'm very new to Selenium.
I'm crawling data from this page. I need to scroll down the page and click on "Load More Arguments" to get more text. This is the location to click on.
<a class="debate-more-btn" href="javascript:void(0);" onclick="loadMoreArguments('15F7E61D-89B8-443A-A21C-13FD5EAA6087');">
Load More Arguments
</a>
I have tried this code but it does not work. Should I need more code to locate to that (I think the 1 has already tell the location to click). Do you have any recommendation? Thank you in advance.
[1] btn_moreDebate = driver.find_elements_by_class_name("debate-more-btn")
[2] btn.click()
Find the link by link text, move to the element and click:
from selenium.webdriver.common.action_chains import ActionChains
link = driver.find_element_by_link_text('Load More Arguments')
ActionChains(browser).move_to_element(link).perform()
link.click()
If you get an exception while finding an element, you may need to use an Explicit Wait:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Load More Arguments")))
ActionChains(browser).move_to_element(link).perform()
link.click()
If I understand your code correctly, I can see a few things wrong.
1. You're using find_elements_by_class_name. I'd recommend using find_element_by_class_name instead. elements returns a list, which isn't needed in a case where there is only one element.
2. You're using btn_moreDebate as the holder for the results of your find_elements, but then interacting with btn.
You should be able to perform the find and click in one action:
driver.find_element_by_class_name("debate-more-btn").click()