Is there a way to fire off the use of the chrome and gecko webdriver at the same time without duplicating code?
Right now I'm swapping between the two.
from selenium import webdriver
from selenium.common.exceptions import
def setUp(self):
# self.browser = webdriver.Firefox()
self.browser = webdriver.Chrome()
Yes, you can do it. However there must be some place where you specify the browser to be opened.
Browser name to be opened can be passed as an argument to setup method
from selenium import webdriver
def setUp(self, browserName):
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
Browser name to be opened can be read from some configuration/properties file.
from selenium import webdriver
def setUp(self):
browserName = #Code to read value from configuration file
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
You haven't specified the environment, so I'll go with this. This is how it could be done in Katalon Studio:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver1 = new ChromeDriver()
WebDriver driver2 = new FirefoxDriver()
DriverFactory.changeWebDriver(driver1)
// test with Chrome
DriverFactory.changeWebDriver(driver2)
// test with Firefox
Related
I stored it in d Drive and gave loction of webdriver but it gives an error
from selenium import webdriver
chrome_driver_path = "D:\chromedriver.exe"
url = "https://www.linkedin.com/jobs/search/?f_LF=f_AL&geoId=102257491&keywords=python%20developer&location=London%2C%20England%2C%20United%20Kingdom&redirect=false&position=1&pageNum=0"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("url")
you should try this: driver.get(url)
not this: driver.get("url")
I have spent much time to find a way to perform right click with appium python client on a application in windows platform. Unfortunately, I get the following exception:
selenium.common.exceptions.WebDriverException: Message: Currently only pen and touch pointer input source types are supported
My code is in the following lines:
import unittest
from typing import List, Optional, Tuple, TypeVar
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
class SimpleCalculatorTests(unittest.TestCase):
#classmethod
def setUpClass(self):
# set up appium
desired_caps = {}
desired_caps["app"] = "Root"
desired_caps["deviceName"] = "WindowsPC"
desired_caps["platformName"] = "Windows"
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities=desired_caps)
#classmethod
def tearDownClass(self):
self.driver.quit()
def test_initialize(self):
communation_object = self.driver.find_element(By.XPATH, "/Pane[#ClassName=\"#32769\"][#Name=\"Desktop 1\"]/Window[#Name=\"ETS5™ - Neues Projekt\"][#AutomationId=\"windowApplication\"]/Custom[#AutomationId=\"eTS4UC\"]/Custom[#ClassName=\"Workspace\"]/Custom[#ClassName=\"ContentPanelContainer\"]/Custom[#AutomationId=\"Control\"]/Custom[#ClassName=\"ActiveComObjectDetailView\"]/DataGrid[#ClassName=\"DataGrid\"]/DataItem[#ClassName=\"DataGridRow\"][#Name=\"21: Ventilausgang 1 (Bezeichnung) - Eingang - Stellgröße\"]/Custom[#ClassName=\"DataGridCell\"][#Name=\"Ventilausgang 1 (Bezeichnung) - Eingang\"]/Text[#ClassName=\"TextBlock\"][#Name=\"Ventilausgang 1 (Bezeichnung) - Eingang\"]")
actions = ActionChains(self.driver)
actions.context_click(communation_object)
actions.perform()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleCalculatorTests)
unittest.TextTestRunner(verbosity=2).run(suite)
Is there any alternative to perform right click?
How to extract Persian texts with Selenium in Python??
The name variable should be text, but it seems to be empty
from selenium import webdriver
from selenium.webdriver.common.by import By
website="https://www.digikala.com/product/dkp-3628808/%D8%B1%D9%88%D8%BA%D9%86-
%D8%B2%DB%8C%D8%AA%D9%88%D9%86-%D8%A8%DB%8C-%D8%A8%D9%88-
%DA%A9%D8%B1%DB%8C%D8%B3%D8%AA%D8%A7%D9%84-%D8%B7%D9%84%D8%A7%DB%8C%DB%8C-3000-
%D9%85%DB%8C%D9%84%DB%8C-%D9%84%DB%8C%D8%AA%D8%B1/"
driver = webdriver.Chrome(executable_path=r"C:\Users\Qazal\anaconda3\Lib\site-
packages\selenium\chromedriver.exe")
driver.get(website)
name=driver.find_element(By.XPATH,'//div[#class="mr-
4"]//a[#href="https://www.digikala.com/seller/AEVNX/"]')
name=name.text
name=name.encode("utf-8")
print(name)
The Xpath expression //*[#class="mr-4"]/div/a/p is producing the following output:
*emphasized text*from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
webdriver_service = Service("./chromedriver") #Your chromedriver path
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
url='https://www.digikala.com/product/dkp-3628808/%D8%B1%D9%88%D8%BA%D9%86-%20%20%D8%B2%DB%8C%D8%AA%D9%88%D9%86-%D8%A8%DB%8C-%D8%A8%D9%88-%20%20%DA%A9%D8%B1%DB%8C%D8%B3%D8%AA%D8%A7%D9%84-%D8%B7%D9%84%D8%A7%DB%8C%DB%8C-3000-%20%20%D9%85%DB%8C%D9%84%DB%8C-%D9%84%DB%8C%D8%AA%D8%B1/'
driver.get(url)
driver.maximize_window()
time.sleep(5)
for name in driver.find_elements(By.XPATH,'//*[#class="mr-4"]/div/a/p'):
print(name.text)
Output:
سراج احسان
رزاقی
I'm starting to automate some processes and have problems with my code. I saw a tutorial of selenium but when i want to run the code, Visual Studio Code give me this Error:
ERROR: test_buscar (__main__.usando_unittest)
AttributeError: 'usando_unittest' object has no attribute 'driver'
This is my code
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import time
class usando_unittest(unittest.TestCase):
def setup(self, driver):
self.driver = webdriver.Chrome(executable_path=r"C:PATH")
def test_buscar(self):
driver = self.driver
driver.get('http://www.google.com')
self.assertIn('Google', driver.title)
elemento = driver.find_element('id','input')
elemento.send_keys('Selenium')
elemento.send_keys(Keys.RETURN)
time.sleep(2)
assert'No se encontro el elemento' not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == '__main__':
unittest.main()
For privacy, I didn't put the PATH in the code.
I need Help Please.
Thanks
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
public class Demo {
AndroidDriver driver =null;
DesiredCapabilities capabilities;
File app = new File("/data/app/com.philips.sleepmapper.root-1/base.apk");
#Test
public void invokeApp() throws MalformedURLException
{
capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("paltformName", "Android");
capabilities.setCapability("platformVersion", "6.0.1");
capabilities.setCapability("deviceNmae", "Galaxy S6");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage","com.philips.sleepmapper.root");
capabilities.setCapability("appactivity","com.philips.sleepmapper.activity.SplashScreenActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
}
When executing this code i am getting the following error:
FAILED: invokeApp org.openqa.selenium.SessionNotCreatedException: A
new session could not be created. (Original error: Bad app:
C:\data\app\com.philips.sleepmapper.root-1\base.apk. App paths need to
be absolute, or relative to the appium server.
The path to your application APK is set incorrectly. I need to know your file structure to give the exact answer, but this is what I think is wrong.
Most likely you are trying to provide the application at C:\path\to\my\project\data\app\com.philips.sleepmapper.root-1\base.apk
If you run Appium in C:\path\to\my\project and you try to pass the relative path to the APK, you are missing the dot in the Appium test code. Change the path in the code to
File app = new File("./data/app/com.philips.sleepmapper.root-1/base.apk");
To make it work from any folder (absolute path) change the code to
File app = new File("C:\path\to\my\project\data\app\com.philips.sleepmapper.root-1\base.apk");
Remember to replace path\to\my\project with the real path you are using.