from invalid argument: 'value' must be a single Unicode code point error using ActionChains class of Selenium through Python - python-3.x

File "C:/Users/User/Test.py", line 58, in <module>
.send_keys(DTD) \
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
from invalid argument: 'value' must be a single Unicode code point
This is the error I encountered when I send_keys to Date filed on Chrome browser.
The followings are my data and part of code.
Data
Part of code
wb = pandas.read_excel(excel.xlsx)
Journal = wb.values.tolist()
for JV in Journal:
DTD = str(JV[0]) #Date
Actions(driver) \ #Make entry to the filed on google chrome browser
.send_keys(DTD) \
.perform()

This error message...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
from invalid argument: 'value' must be a single Unicode code point
...implies that there was a compatibility issue while converting a non w3c command to w3c standard command.
As per the discussion in ActionChains perform returns exception 'value' must be a single unicode point this issue was observed with appium Version 1.11.1 when used along with ChromeDriver v2.45 setting the standards mode with:
goog:chromeOptions.w3c:true
Excert from release notes:
Resolved issue 2536: Make standards mode (goog:chromeOptions.w3c:true) the default [Pri-2]
Solution
An immediate solution would be to:
Update ChromeDriver to current ChromeDriver v78.0 level.
Update Chrome to current Chrome Version 78.0 level. (as per ChromeDriver v78.0.3904.105 release notes)
tl; dr
A couple of relevant discussions are as follows:
perform() action chain - Getting exception
ActionsChains key_action.pause causes "exception 'value' must be a single unicode point" in Appium Webview or Chromium

Related

Python Selenium Remote Webdriver Upload File

I am using python 3.9 and selenium 4.6.0 on Chrome. I have a script that needs to upload a file to an input, this works fine on local but fails when run on RemoteDriver. The code I am using is
driver.find_element(By.XPATH, "//input[#accept]").send_keys('path to file')
When run on RemoteDriver the error returned is
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/cddd71e067d7717481fb8a635103c643/se/file
I've think it is due to this line in the remote_connection.py file in selenium
Command.UPLOAD_FILE: ('POST', "/session/$sessionId/se/file")
From the research I've done the 'se' in this case is a 'vendor_prefix' for selenium but I cannot figure out how to either configure the remote driver to use a vendor prefix or remove that from POST path that is being passed (short of pulling my own version of the code and maintaining that).
For other functional reasons I can't revert to selenium 3x (which is an option I've seen to correct this), nor can I set w3c to False. Does anyone know how to work around this particular issue; either by getting send_keys to operate as expected in this situation or using another method to upload the file? Thanks.

Python + Selenium find_element_by_xpath returns dict

-Version-
Python : 3.6.8
Selenium : 3.141.0
I try this.
total_page = driver.find_element_by_xpath('Valid X Path').text
print(total_page)
but,
AttributeError : "dict' object has no attribute 'text'
I Knew....
The find_element~ function returns Dict type, not WebElement.
What could be wrong?
I am also facing the same issue when I am using Chromedriver. The workaround I am currently using is to use another driver (in this case Firefox works for me).
EDIT: I tried to uninstall and reinstall the latest chromedriver and that seems to fix the problem for me as well.
Try to avoid using
total_page = driver.find_element_by_xpath('Valid X Path').text
and change on new way, coz that one will be deprecated in the future:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
el = driver.find_element(By.XPATH, "valid_xpath")
print(el.text)
anyway, I see the problem, but is not reproduced for me...
This error message...
AttributeError : "dict' object has no attribute 'text'
...implies that find_element_by_xpath() is returning a dict type of object which is a bit unexpected and something is wrong somewhere within your code.
Deep Dive
This error started showing up recently in some of the usecases:
where as #titusfortner mentions find_element() was returning JSON Wire Protocol signature for elements instead of a w3c response from the driver.
This issue can be reproduced with w3c set as False as follows:
options.add_experimental_option('w3c', False)
Recomendations
In such cases, it is recommended:
Not to set w3c at all and go as per the default configurations.
Do not use the desired_capabilities key
Avoid bypassing the sandbox security unless you got a specific usecase to do so.
However, it is also important to ensure that:
Selenium is upgraded to current release of Version 4.1.3.
ChromeDriver is updated to current ChromeDriver v99.0 level.
Chrome Browser is updated to current chrome= 99.0 (as per chromedriver=99.0 release notes).

How to use specific Chrome profile with selenium python

Please don't mark this is as duplicate first read my problem properly..
This is my code:
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\\Users\\Pranil.DESKTOP-TLQKP4G.000\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument(r'--profile-directory=Profile 1')
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
browser.get('https://web.whatsapp.com')
And this is the error I get:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
I tried the solutions given here:
InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium
The problem is that the Default and Profile 1 are in the same directory User Data(Creating a new profile doesn't solve the problem as mentioned in above answer)..So if I run this script with my another chrome tab with 'Default' profile running in background this error appears..How can I make sure that this error goes away(I can't close the other chrome tabs with Default profile while running this script)

Expected type 'dict', for 'str' instead PyCharm. Trying to convert all PDF pages into CSV using tabula?

my code can convert only one upper part of my PDF first sheet, when I am tying to convert all pages I can't because I get the error in my code.
import tabula
tabula.convert_into("/Users/gfidarov/Desktop/Python/KH_Profilansicht_13.11.2019-2.pdf", "/Users/gfidarov/Desktop/Python/test.csv", output_format="csv",pages='all')
The error which I get is about the pages function
when I am writing it PyCharm says Expected type 'dict', for 'str' instead
I am using python 3.x version in my PyCharm.
Is there other ways how to choose all pages to convert not only upper side of first page
Do you have a runtime error? PyCharm complain is just a warning one can "safely" ignore. The problem is tabula.convert_into has an incorrect docstring type annotation:
kwargs (dict)
should be e.g.
kwargs (str)
See https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values

Cucumber-Capybara: save_screenshot(path, full: true) is not capturing the full browser?

I'm using the latest Chrome browser, Version 57.0.2987.133 (64-bit), with the latest chromedriver v2.29 (although I've tried with Chrome 56 and chromedriver 2.27 as well) and I've got a problem where I am not able to capture the full browser when a test fails.
This is the code I've got on my env.rb file:
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path, full: true)
end
However, the screenshots I am getting are just a partial part, what I can see on the screen rather than the complete browser.
Any idea if I'm doing something wrong or if I can try something different?
Thank you!
Since you're using chrome, I assume you're using the selenium driver (selenium-webdriver). The selenium driver doesn't support any options being passed to save_screenshot, and passing options to page.driver.screenshot -https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb#L34 - will raise a too many arguments error (which in your case I assume the capybara_screenshot gem catches and ignores) and not save a screenshot. If instead you call driver.save_screenshot(path, full: true) it will take a shot, but any options passed will be ignored since they aren't supported. Additionally, since the WebDriver spec is defined as taking a shot of the viewport (visible window), I would not expect selenium to support full screen shots any time soon.
If you are using selenium for your screenshots and you want larger your only option is to increase the window size before taking your screenshot.

Resources