I was trying to insert a js code into a website using selenium.
I know that I want to use the following import statement,
import org.openqa.selenium.JavascriptExecutor
But this was not installed,
"org.openqa.selenium.JavascriptExecutor" is not accessed
Import "org.openqa.selenium.JavascriptExecutor" could not be resolved
where to install the module or how to resolve the problem
You have tagged python and using the Selenium-Python clients you don't require any additional import other then from selenium import webdriver as both the methods to execute JavaScript synchronously and asynchronously i.e.
execute_script()
execute_async_script()
are supported out of the box.
Where as incase you are using the Selenium-Java clients you additionally need to import:
import org.openqa.selenium.JavascriptExecutor;
Related
Question.
I am a noob, what is the difference between this:
import selenium
And this
from selenium import webdriver.
Doesn't import selenium automatically import webdriver?
Yes it does but the use is different.
When you type from selenium import webdriver you can access it by typing webdriver in your code.
But when you run import selenium you can access webdriver by typing selenium.webdriver.
Sometimes you want to make clear where this function is from like in django urls I always type from . import views so I can then type views.myfunction in code.
For import selenium, names are accessed via selenium.nameX. You also have access to the entire selenium package.
With from selenium import webdriver, you are importing only webdriver from the selenium package. You do not have access to the entire selenium package. In the second case, you also access names from webdriver via webdriver.nameX, not selenium.webdriver.nameX.
yes but if you just import selenium you would have to do selenium.webdriver.functionyouwant instead of just webdriver.functionyouwant
When you type import package, you can access module by typing package.module.
When you type from package import module, you can access module by typing module and you can't use other modules in package package.
I have a simple python program, that is supposed to scrape some information from the internet and do stuff with it. When I run the code in PyCharm (IDE) it works fine, but when I run it directly it doesn't work (Right-click -> Open with -> Python). In order to find the error I put several input statements in the code, as such:
from random import choice
input(1)
import webbrowser as web
input(2)
from time import sleep
input(3)
import pyautogui as pg
input(4)
from platform import system
input(5) # It closes after this.
from bs4 import BeautifulSoup
input(6)
import requests
input(7)
It all seems to work fine until 5. I press enter then the terminal instantly closes without any error messages. So there must be something wrong when I import BeautifulSoup from bs4.
from bs4 import BeautifulSoup
Why does the python terminal close when executing the import statement? Any help would be appreciated :)
This is probably due to an exception that is terminating the process. I had the same problem a while ago and it was solved by installing the package.
Are you sure you have bs4 installed? Try running pip install bs4 to make sure it is installed.
I am trying to use the Select function in Selenium for Python 3 to help with navigating through the drop down boxes. However, when I try to import org.openqa.selenium.support.ui.Select I get an error message:
"No module named 'org'"
Would appreciate any help on this. I saw there was a similar question posted a few weeks ago but the link to that question is now broken. Thanks!
The path 'org.openqa.selenium.support.ui.Select' is a Java descriptor. In Python, make sure you have the Python Selenium module installed with pip install selenium, and then import it with import selenium.
For the Select function specifically, you can import that with the following
from selenium.webdriver.support.ui import Select
Then you'll be able to use it like this:
select = Select(b.find_element_by_id(....))
I'm going to make an application using the Selenium WebDriver (python) and I was having trouble with some of the initial setup. I want to use the page object design pattern so I've been trying to import some materials in this way:
from page_objects import PageObject, PageElementfrom page_objects import PageObject, PageElement
as can bee seen in the documentation here: https://page-objects.readthedocs.io/en/latest/tutorial.html#a-simple-page-object
I'm using PyCharm for development and I've updated selenium and added it to the project interpreter but this import statement still will not work for me. I'm not sure which external module this import relates to or if its just some part of selenium, so any information would be greatly appreciated. Thanks!
That readthedocs is for the page_objects library, the repo for that library can be found here. You need to install that library before you can import it
I have a Python script that wants to use BeautifulSoup:
from bs4 import BeautifulSoup
When I run the script from the command line, it works fine. When I run the script externally, from a browser, it dies on that line. The web logs say:
ImportError: No module named bs4
I've also tried, with the same result:
import bs4
import BeautifulSoup
I installed the module from a tarball, and it now resides in a folder that is in my Python path:
/usr/home/myName/.local/lib/python2.7/site-packages/
I have made sure the permissions for the bs4 directory, and all .py and .pyc files in the folder allow execution (chmod 775 *.py), and I've checked to see that both internally and externally the same version of Python is being run (2.7.9 (default, Jan 12 2015, 16:33:18)
[GCC 4.2.1 20070719 [FreeBSD]])
You have not installed BeautifulSoup for the benefit of all the users on your computer. Instead, you installed only for the benefit of the user named "myName". In particular, you haven't installed it for the use of the user that runs the web server (often named 'www' or 'www-data').
If you can, install BeautifulSoup in the system-wide location.
Otherwise, you can modify your script like so:
import sys
sys.path[0:0] = ['/usr/home/myName/.local/lib/python2.7/site-packages/']
from bs4 import BeautifulSoup
Thanks to #robᵩ (phi) for pointing out what was wrong: because this script was on a shared server, I was unable to give execute permission to the "user" running the web server (in this case, "nobody"). I was able to run the script using ssh, since I was the user in that case.
Because I was unable to convince the hosting service to install BeautifulSoup for all users, I ended up using a different library, lxml.html, which my host server does install with Python.
(I found lxml.html a pleasure to work with, as well)