have a special web page can't find any elements - python

The website is https://www.gaitame.com/bo/demo.html
in middle have a button with japanese "デモトレード版を利用する"
then will be go to a demo trader page like this
in this page i cant get any elements
other page is all right
i already switch_to this tab
please help.............
here is my testing code
from selenium import webdriver
import time
url = 'https://www.gaitame.com/bo/demo.html'
driver = webdriver.Chrome()
driver.get(url)
# Click the button and wait for loading
driver.find_element_by_class_name("blue2btn").click()
time.sleep(5)
# Switch to another tab
driver.switch_to.window(driver.window_handles[1])
# Try find any elements
driver.find_elements_by_class_name("header_area")
this is error msg
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-ed6cc8fa6e76>", line 14, in <module>
driver.find_elements_by_class_name("header_area")
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 580, in find_elements_by_class_name
return self.find_elements(by=By.CLASS_NAME, value=name)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1007, in find_elements
'value': value})['value'] or []
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: Unsupported locator strategy: null
(Session info: chrome=80.0.3987.132)

This is a newly introduced Chromedriver bug.
Try using an older version of Chrome or another browser. I just tried your code in Firefox 73 and it worked.
Hope this helps and good luck!

the bug seems to still be in chromedriver.
it's related to switching to a new window or tab.
However, in the OP's post, I don't see how he created the 2nd tab. he just switches to the tab/window with this
driver.switch_to.window(driver.window_handles[1])
It's possible the original problem here, was not creating the 2nd tab/window correctly.
Or it could be the existing chromedriver problem (which is intermittent/dependent on web page)
see here https://bugs.chromium.org/p/chromedriver/issues/detail?id=3390
The exception I'm tracking (which the OP reported) is this
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: Unsupported locator strategy: null

Related

Click on DIV with selenium [duplicate]

This question already has an answer here:
"unknown error: cannot read property 'scrollleft' of null" in Chrome using selenium
(1 answer)
Closed 3 years ago.
I'm trying to click on "retweet" with selenium.
I found this way with javascript:
document.querySelector('[data-testid="retweet"]').click()
document.querySelector('[data-testid="retweetConfirm"]').click()
So I implemented in selenium with something like this:
firstJS = "document.querySelector('[data-testid=\"retweet\"]').click()"
secondJS ="document.querySelector('[data-testid=\"retweetConfirm\"]').click()"
time.sleep(5)
driver.execute_script(firstJS)
time.sleep(3)
driver.execute_script(secondJS)
and i get this error:
Traceback (most recent call last):
File "C:\Users\Riccardo\Desktop\ProxyGiveaway\config.py", line 75, in <module>
main()
File "C:\Users\Riccardo\Desktop\ProxyGiveaway\config.py", line 67, in main
retweet(link, driver)
File "C:\Users\Riccardo\Desktop\ProxyGiveaway\config.py", line 43, in retweet
driver.execute_script(firstJS)
File "C:\Users\Riccardo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "C:\Users\Riccardo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Riccardo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'click' of null
(Session info: chrome=1.2.3.4)
EDIT: I added some time.sleep() and the first line works, but not the second
This might be due to page loading try adding wait until page load.

How to fix this issue element not interactable Selenium Python

I have the following line in my script code, where the XPath I got it from Selenium IDE that works fine:
driver.find_element_by_xpath("(//a[contains(#href, '')])[20]").click()
An automation test stops here with this error:
Traceback (most recent call last):
File "Script.py", line 65, in <module>
driver.find_element_by_xpath("//a[contains(#href, '')])[20]").click()
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Windows NT 6.1.7601 SP1 x86_64)
How to fix this issue?
Thanks for any help.
Seeing as you just want to scrape the data, I recommend you use this solution:
element = driver.find_element_by_xpath("(//a[contains(#href, '')])[20]")
driver.execute_script("arguments[0].click();", element)
Which clicks the element via Javascript as opposed to a "natural" click that selenium uses (to try to simulate the user experience).
I answered a similar question here that links to another post on it as well.
Sometimes you may need to copy Full XPATH. That was one work around I found.
I would like to share my experience on that in case someone else had same scenario.
I received same error message "Message: element not interactable".
And after like two hours of troubleshooting it turned out that there was another hidden element identified by XPATH. So, I modified my XPATH to ensure capturing targeted element only.
I was able to fix this issue with using full Xpath instead of x path for anyone coming here in the future I hope this will help. I think the reason for this is the element I wanted to click was wrapped by another element so it was not interactable

How to find elements of a modal pop up window with Selenium Webdriver

I am using Selenium webdriver with firefox to download real states data from a website. Once the inputs are entered a pop up window will ask to either select 'Cancel' or 'Save File'.
The problem is that I'm not able to find how to 'click' these buttons. I know it is already the current window in my driver because I am able to change the enter image description here position.
If I dodriver.find_element_by_xpath('//*'), this is the error I get:
Traceback (most recent call last):
File "<ipython-input-131-e87e382e3fb9>", line 1, in <module>
driver.find_element_by_xpath('//*')
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 295, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 756, in find_element
'value': value})['value']
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 238, in execute
self.error_handler.check_response(response)
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py",
line 193, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchWindowException: No such content frame; perhaps the listener was not registered
I've searched on the web for solutions and most of them mention switching to alert, driver.switch_to_alert().accept(). This is the error I'm getting:
Traceback (most recent call last):
File "<ipython-input-142-bd939a2be33d>", line 1, in <module>
driver.switch_to_alert().accept()
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/common/alert.py",
line 81, in accept
self.driver.execute(Command.ACCEPT_ALERT)
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 238, in execute
self.error_handler.check_response(response)
File
"/home/rcortez/anaconda2/envs/webscraper/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py",
line 193, in check_response
raise exception_class(message, screen, stacktrace)
NoAlertPresentException: No tab modal was open when attempting to get the dialog text
This issue is very similar to Not able to locate element on a modal pop up window : selenium, but I don't understand how the accepted answer there was able to find the selectors.
Any ideas how to solve this issue would be greatly appreciated.

CLOSED - Python Selenium Can't find elements

I have a problem with selenium with python 3.5, after install all the windows updates all my selenium script broken, I receive every time the same error:
Traceback (most recent call last):
File "C:/Users/Carlo/Desktop/CEx/src/IE.py", line 12, in
a=driver.find_element_by_xpath("//*[#id='un']")
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Unable to find element on closed window
But I really don't understand why because the window of IE is open!
This is my code (simple just to check why I can't make it work more):
import time from
selenium import webdriver
driver = webdriver.Ie()
driver.get('http://gala.test-platform.celtrino.com/Login.aspx')
time.sleep(10)
driver.find_element_by_xpath(".//*[#id='un']")
The code fail every time in the last line and I double check with firepath and the xpath is correct so I don't really understand why it's not working.
I knew, IE has problems with xpath. It does not support xpath directly. It needs third party tools to do this. So, I suggest you to try cssSelector or any other options instead. Since, the element has an ID so you could use this. It's better.
driver.find_element_by_id("un");

Selenium - Element is Not Visible [Python]

I'm currently in CH11 from the "Automate the Boring Stuff with Python" book and I'm going over the Selenium module. I'm trying to move to the end of a page but I'm getting some problems. I also tried to look similar problems in this site and tried the solutions suggested without success unfortunately. Here's my code, when I type it into the IDLE Shell:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser= webdriver.Firefox()
browser.get('http://nostarch.com')
htmlElem= browser.find_element_by_tag_name('html')
type(htmlElem)
<class 'selenium.webdriver.firefox.webelement.FirefoxWebElement'>
htmlElem.send_keys(Keys.END) # Error
Exception -:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
htmlElem.send_keys(Keys.END)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
return self._parent.execute(command, params)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not visible
Apparently the html element is not visible? I don't understand how so since it seems to locates the html element just fine as seen on the code without any problems but the Key.ENTER is where I'm getting the error.
Any help would be appreciated.
Just tested the following with Chrome driver and it works (It should also work with Firefox):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('http://nostarch.com')
body_elem = browser.find_element_by_tag_name('body')
body_elem.send_keys(Keys.END)

Categories