Python Selenium Remote Webdriver Upload File - python-3.x

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.

Related

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).

Why pandas profiling isn't showing any output in ipython?

I've a quick question about "pandas_profiling" .So basically i'm trying to use the pandas 'profiling' but instead of showing the output it says something like this:
<pandas_profiling.ProfileReport at 0x23c02ed77b8>
Where i'm making the mistake?? or Does it have anything to do with Ipython?? Because i'm using Ipython in Anaconda.
try this
pfr = pandas_profiling.ProfileReport(df)
pfr.to_notebook_iframe()
pandas_profiling creates an object that then needs to be displayed or output. One standard way of doing so is to save it as an HTML:
profile.to_file(outputfile="sample_file_name.html")
("profile" being the variable you used to save the profile itself)
It doesn't have to do with ipython specifically - the difference is that because you're going line by line (instead of running a full block of code, including the reporting step) it's showing you the object itself. The code above should allow you to see the report once you open it up.

Google Colab - downloads some files, TypeError: Failed to fetch on others

I have a Google Colab notebook with PyTorch code running in it.
At the beginning of the train function, I create, save and download word_to_ix and tag_to_ix dictionaries without a problem, using the following code:
from google.colab import files
torch.save(tag_to_ix, pos_dict_path)
files.download(pos_dict_path)
torch.save(word_to_ix, word_dict_path)
files.download(word_dict_path)
I train the model, and then try to download it with the code:
torch.save(model.state_dict(), model_path)
files.download(model_path)
Then I get a MessageError: TypeError: Failed to fetch.
Obviously, the problem is not with the third party cookies (as suggested here), because the first files are downloaded without a problem. (I actually also tried adding the link in my Allow section, but, surprise surprise, it made no difference.)
I was originally trying to save the model as is (which, to my understanding, saves it as a Pickle), and I thought maybe Colab files doesn't handle downloading Pickles well, but as you can see above, I'm now trying to save a dict object (which is also what word_to_ix and tag_to_ix) are, and it's still not working.
Downloading the file manually with right-click isn't a solution, because sometimes I leave the code running while I do other things, and by the time I get back to it, the runtime has disconnected, and the files are gone.
Any suggestions?

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.

TinyTag import error python 3.3

I have been trying to import tinytag into python to be able to read mp3 tags but I keep receiving the same error. This is the code I am running
from tinytag import TinyTag
tag = TinyTag.get('/some/music.mp3)
print(tag.album)
and the error I recieve from this is
ImportError: No module named 'tinytag'
If anyone could give me any information on how to fix this would be greatly appreciated or can suggest another reader to use that is compatible with python 3.
Like you, I'm new to Python and I struggled with this but I worked it out eventually. I'm sure there is better way, but this worked (on windows, with my examples)
I installed a python module called easy_install (bundled with
setuptools). you can Google this. In the directory \Python26\Scripts you should see an exe file called easy_install if this has worked
Then I downloaded TinyTag to my pc eg
\downloads\tinytag-0.6.1.tar.gz
Then in note pad I wrote a small text file called myinstall.bat with
the contents
easy_install C:/downloads/tinytag-0.6.1.tar.gz
pause
then saved it into \Python26\Scripts and ran it (the pause keeps the
window open so you can see it worked)
Subsequently I started using some software called JetBrains to code with (it's commercial but there is a free edition) and that has an install tool built in which is even easier) I hope this helps

Resources