How to Import Shopify Data into Prestashop with CSV

Brutal. I spent probably 3 hours trying to figure this out so I thought I should spend about 10 minutes and write this quick blog post for anyone else who might hit this.

I was testing out Prestashop (looking good so far!) and the aim was to move a new shopify account over to Prestashop to see how it goes.

First thing I did was had the Shopify product data exported as .csv file.

Next I followed the instructions on the documentation page for importing into Prestshop. Unfortunately, though, there seemed to be no detailed instructions about how to set up data. I think this is because there are a lot of migration companies that make some cash doing this so fair enough.

Anyways, what I did was opened up both Shopify .csv and Prestashop demo .csv for products and noticed that they both have different data separator formats.

Shopify uses commas whereas Prestashop uses semi colon.

So, all I had to do was manually type in a comma into the field that says ‘Field Separator’ in the Prestashop import module and everything started working and I could start mapping the fields and database tables as expected and as explained in documentation.

Hope this tiny, one second tip helps you save 3 hours and some cash.

Tags : , , , ,

Getting Korean Hangul Working on Ubuntu 18 and higher

How to install Korean Hangul Keyboard Ubuntu Gnome 18

In Ubuntu there are two things that need to happen to be able to type a non-native language into the operating system. You need to get the fonts and the stuff and you then need to configure stuff so the keyboard knows what to do. Without doing both, nothing will work and you’ll think things are broken.

Part 1 – Getting your Korean Language Fonts and Stuff Installed on Machine

  1. super key (sometimes erroneously called the ‘windows key’)
  2. start typing’languages’
  3. Select ‘language and region’ option (may not be top, largest option)
  4. Click the’manage installed languages’ button
  5. If you get the ‘language support is not installed completely select ‘install’. you will be prompted for your admin pass
  6. Click the ‘install/remove lanaguages’ button (on the same ‘Language SUpport’ window. NOTE: This window seems to get easily hidden by other stuff but you can find it again easily in the left launcher while it’s open)
  7. Start typing ‘Ko..’ to trigger the search of ‘Korean’ language when the list of language and their checkboxes appear
  8. select ‘Korean’ and ‘apply’ you will again be prompted for your admin pass. If you are coming from another less secure operating system this is about securing your computer against weird scripts and making sure what is happening is authorized…At this point fonts start downloading and the ‘applying changes’ window is on your screen. This takes a little while sometimes.

Remember, nothing will work yet. You have to do the next section 😉

Now, important little tip here. You need to REBOOT your system now to assure that the input sources in the next steps are refreshed. I cannot tell you how many hours I have burned on this one so just to be sure, take a second to reboot the machine now before continuing.

Part 2 – Getting Input Source Setup So You Can Actually Use the Language

  1. On the same page ‘Language and Region’, under ‘Input Sources’ section, hit the plus + button. I should state here that if for some reason you aren’t seeing what I”m seeing here, just hit your super key and then ‘settings’ and then go to “language & Region” from there. Sometimes stuff moves around…
  2. Hit the 3 dot vertical hamburger icon looking option at the bottom of the list… admittedly this step and the next are not intuitive so feel free to file a GUI suggestion with the fine folks who make Gnome. 🙂
  3. By hitting that option a search field opens up which you’d think would allow you to type ‘Korean’ or ‘Hangul’ and then find your language – but in this case you’d be incorrect for thinking that. What you need to do is scroll to the bottom of this list and selecting ‘Other’. You can alternatively type ‘Ot’ into the search field here…but you cannot type anything more than ‘Ot’ Admittedly this part is plain bad for design… so probably just use the scroll feature here to avoid thinking it’s missing, lol.
  4. Now you are able to use the search field to type ‘Korean’ and / or scroll down to find it. So go ahead and do that now…
  5. You wil see ‘Korean’ and “Korean(101/104 key compatible)” but those are just decoys! Pure deception! The one you want is called “Korean(hangul)”. I have no idea what the other ones are or do but I do know they don’t work for me. Again, if you don’t see this specific option now, you probably didn’t listen to me above and didn’t reboot your machine so be a good student and go ahead and reboot that now…

After it’s highlighted in your list, select the ‘add’ button which should change to a green colour when it’s ready. You should now be brought back to the “Language and Region’ screen and see ‘Korean(Hangul)’ in your list of ‘Input Sources’ You should also notice in the top right area where your wifi, battery, other stuff is that the symbol for your native language has appeared with a drop down arrow. In my case it’s English so I see ‘en’ with the down arrow.

Technically now you have Korean installed and a keyboard input ready to go but a quick tutorial on setting up and using it is probably wise…

Setting up and Using Korean Keyboard

Probably, if you’re like me, you’ve already hit the down arrow, switched to the ‘Ko’ (Korean) option and started typing only to find that it’s still typing English. Why is that after all this work? Because Korean keyboard input is able to type both English and Korean so you have to be able to – while in KO mode – switch back and forth. So what keys do that?

First, let’s take a look at how to switch between input sources. On the Language & Region screen, if you hit the ‘Options’ button (which appeared after you installed Korean) you can now see the key combos to switch between ‘en’ and ‘ko’. This is useful because I find that most of the time I want to be in ‘en’ because my fingers sometimes switch me to Korean accidentally during the day when I don’t need it. The default combo is ‘super’ + space bar. What is ‘super’? See above. It’s the powerful key to the left of the space bar sometimes erroneously called the ‘windows key’. Hit that with space bar and you’ll be able to switch.

Next, while in ‘korean mode’ how to switch between English and Korean? The default appears to be ‘shift + space bar’ (while in Korean mode).

You can make this combo whatever you want by one of two methods:
a) while in Korean mode, hitting the top ‘EN’ drop down in top menu of screen. This will then give you the IBUS ‘setup’ option. I like this way to adjust things. However you can also find it by
b) going to language and Region page, highlighting Korean(hangul) in input sources and hitting the settings cogwheel. Same-same….

Nice. Now you’re typing 강남 style.

Hope this helps. Should have made a video but yeah whatever too late.

Tags : , ,

GETTING A QUASAR BUILD RUNNING AS APP ON UBUNTU TOUCH

Here is my journey to see if I can make a basic Quasar app work on Ubuntu Touch.
I should preface that I have never built an Ubuntu Touch app and I’m not even done my Quasar course
but there are enough people interested in this so I want to stop everything and try…

Quick Overview of Ubuntu Touch Apps and Quasar

To get familar with the Ubuntu Touch directory structure stuff, I git cloned this simple hymnal app since I knew it was mainly based on html website stuff and likely would not have complicated databae backend stuff going on. You may wish to do the same.

Build an Ubuntu Touch App with Clickable

What is clickable? It’s the thing Brian Douglass made, of course. And who is Brian Douglass Brian is just super great and one of the main/only reasons I started learning how to program. Thanks Brian again!!

Here is a link to UBport’s App Development for Ubuntu Touch

I will start by forcing myself to actually read the docs! Painful for a guy like me but I’ve learned that this is the right way to suffer less… I will start by reading all the links in the ‘Guides’ section on the link above.

In there, I found Lionel Duboeuf’s video on clickable. Nice! Thanks, Lionel (another great guy).

First, don’t rely on my commands here that I reference. Always go to the documentation page to make sure they are all updated. I’m just putting them here mainly for my own log.

Part of my journey was discovering that the clickable documentation assumes I would know what order to install dependent packages. Unfortunately that was not true so my journey was a bit painful. I’ll try to spare someone else this part of the journey. The docs instruct to install docker, adb, git and pip3 but it doesn’t say to make sure that you do these first and that the rest won’t work. At least this is what happened to me. So maybe just follow my order:

  1. Install adb (search it online but I recall it was just sudo apt install adb)
  2. Install git (probably sudo apt install git)
  3. Install pip3 (the python thingy that installs more python thingies) so that you can install Clickable. sudo apt install python3-pip should be the right command… but your terminal should tell you if I’m wrong, ha
  4. Install clickable: This page says everything. I’m waiting for an answer on why pip3 install method is recommendd over PPA method. I’m assuming it has to do with docker functionality? Anyway, I’m up and running with the following command so roll with this: pip3 install git+https://gitlab.com/clickable/clickable.git
  5. Install Docker: See dedicated instructions below
  6. Run clickable in the terminal but don’t do so until Docker is fully installed! It requires Docker!

Installing Docker

This part of the process, for me, required a dedicated section and a lot of learning. If you are already set up with Docker you can probably just skip all this. But for those like me who have never used it this section should save you a lot of pain.

Apparently you need the latest ‘engine’ for Docker and for Ubuntu that is found here. This part was pretty painful for me but it doesn’t need to be. I’ll leave a few of my long notes to scan through but you should be good to go to simply run:

sudo apt install docker.io

Feel free to run that and skip this next section if you want.

Installing Docker the Fast Way

As per above: sudo apt install docker.io will install it but it’s better to follow the docker instructions above.

Installing Docker the Long ‘Recommended way’

Setup some preliminary ‘stuff’ with this group of commands:

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Curl the gpg key with this command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Looks like this next one sets up the right repository. Note! You can copy the back slashes and it works just find in terminal (somehow I never knew this…):

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"`

Run this:

sudo apt-get update

And then this:
sudo apt-get install docker-ce docker-ce-cli containerd.io

Finally, run a quick test to make sure it works:

sudo docker run hello-world


EDIT – 200427 apparently this next user section is not needed as it happens when you install Docker. Thanks

But don’t think you’re ready to go just yet! You have to make sure your Ubuntu machine has the right privelidges set for Docker.

Add Docker User to Ubuntu Group

If you know how to ‘add Docker to your user group’ or to check to see if you have it, then go ahead and do that and skip this section. For the rest of us, read on:

Apparently you can see what groups and users you have on your ubuntu machine by using this handy command, but note importantly that the list it outputs is not in alphabetical order:

For users: compgen -u
For groups: compgen -g

If all the Docker install stuff worked you should see ‘docker’ in the list under after running compgen -g

If you don’t, then if you run the following command you can add it. Be sure to replace the $USER – incuding the $ with your Ubuntu machine’s user name.

sudo usermod -aG docker $USER


CLICKABLE TIME – THE MOMENT OF TRUTH

This section now assumes that you have done all the steps above including Docker. Here is a quick review so you can check again:

  1. adb
  2. git
  3. pip3
  4. clickable
  5. docker

Before you do this next step, if possible, make sure you are on a wired connection or the fastest connection you can get. I will explain…

Ok, let’s do this. Type clickable in your terminal.

Note! this part is wacky and doesn’t deliver the usual ‘status’ stuff to know what’s going on and how long it will take. There were a lot of the following kind of messages in the terminal which were normal. Here are some notes I took so that you can feel less ‘curious’ about whether things are progressing or broken:

waiting
Download complete
Verifying Checksum
etc
etc
Download complete

At this ‘Download complete’ message this is where things hung for a long time for me. Apparently what is happening here is that an entire Docker image is being downloaded and set up and this is nearly 1 gigabyte of data.

Pull complete

Once I hit this stage ‘Pull complete’, then there was another batch of messages that included ‘verifying checksum’ and ‘Download complete’ at which point it again paused for a really long time.

After what seemed like forever in my case (bad wifi) it all ended the process.

It’s also interesting to note, but I have not tested, that apparently this long process only happens the first time you set up your app and subsequent updates you make to your app will not require this process, which is nice.

Ubuntu Touch(ing) Your Quasar Package

Now you’ve powered through that process you’re now ready to move your Quasar app to Ubuntu Touch. The good news is that this part is pretty easy! I’ll try to make this more of a step-by-step guide since probably we’ll all need to refer back to it.

Setup your Quasar stuff for the Ubuntu Touch stuff

This assumes you know what quasar build means and that you have have already run it in your quasar directory and have the ‘app’ ready to go. On my machine, the files we need are found in the /dist/spa directory.

  1. Create a directory on your development machine with your Ubuntu Touch app name somewhere logical for later use
  2. In the same directory create another directory called ‘www’ (you can probably call it what you want but might want to keep it ‘www’ for this tutorial for ease). To be honest I think the main purpose of doing this is to keep your source files in a logical spot. At least that’s why I did it…
  3. Go to your Quasar /dist/spa directory and copy all the files from there to the ‘www’ directory you just created in step 2.
  4. Set up your logo file for UT. I think there are two ways to do that so I’ll outline them both with a and b as follows:
    a) stick it in the main directory of your directory you created in step 2 above and give it the title (“icon.png”)
    b) stick your logo file in a logical place then go in and edit your appname.desktop file and point the following line to your icon: Icon=path/to/your/icon.png

Now you have the foundation laid and are ready to build the app

Build the Ubuntu Touch App Pre-Build Structure

  1. In your terminal cd inside your app’s top level directory, run clickable create which will create the structure for your app, not the app itself (the click file). I was mixed up on this for a while so note this.
  2. As Clickable walks you through the process, the key step is to select option 5 (HTML) . The rest of the options are for standard app building processes and details about those can be found if you’d like to learn more or just watch Lionel walk through it in his video.

Move your Quasar files to your Ubuntu Touch app structure

  1. Manually copy/move all the contents of your top level app `www’ directory into the newly-created /YourAppName/www folder (I wonder if we can automate this step later so the build script grabs it?)
  2. Run clickable desktop which gives you a really cool test emulation of the app before you build it. If everything seems to open up and work on your dev machine, continue.
  3. Make sure your Ubuntu Touch device is plugged in by USB (so that it will get the adb push of the app) and recognized. I also discovered there is a handy clickable tool clickable devices to do just that.
  4. Run `clickable’ which will build the app, and push your Quasar app to Ubuntu Touch as a click file. You should now be able to find a newly-created /YourAppName/build directory which should hold your shiny new Quasar appready to publish to OpenStore, or use on your local Ubuntu Touch device for whatever you need.

Success? Let me know if it helped and how the tutorial can be improved as I had to rush it out for someone 🙂

Tags : , , , ,

Getting Started With Quasar and VueJS on Ubuntu

After watching this recommended tutorial I decided to try out this Quasar thing. My true hope is that we can eventually add Ubuntu Touch as one of the buildable outputs at the end of app creation as it apparently might not be that hard with Cordova… but I digress…

I’m not an experienced developer yet so getting started with all these different ‘things’ I had to install with the terminal was getting a bit concerning. I decided to document my journey so that others can hopefully follow along and save some research and time.

So, if your goal is to be able to, without a great deal of pain, create a good looking app to run on Ubuntu, this might just help.

Without further adoo here are the steps that I took to get set up on my Ubuntu 18 LTS machine so that I’m ready to start using the Quasar framework. I left very brief notes to show what you are actually doing so that it’s not some random terminal script from some random blog:

  1. Install npm
    sudo apt install npm
  2. Download and install NVM (a thing to help you install and manage nodejs. Ubuntu repository for NPM is apparently not reliably up to date so that’s why we are using NVM. NOTE: Before beginning, check this page to make sure the following script I’m about to give you is up to date as it changes from time to time. Oh, and if you want to have a dance party and learn more about the details of NVM, this video is good. curl -o https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  3. Install LTS version of Nodejs (you can do whatever version you want as well easily but I’m not bothering to show that in this tutorial): nvm install --lts
  4. Check to make sure what you installed was what you wanted nvm ls
  5. Install the Vue CLI which is apparently what real developers developing VueJS stuff use. I got a few ‘warning’ messages after running this about my OS but probably life will continue…note also that when running this script my whole computer slowed down: sudo npm i -g @vue/cli
  6. Install Quasar – the framework that apparently makes doing a lot of stuff easier: sudo npm i -g @quasar/cli

Now I’m off to try to actually do this tutorial

Some Follow-Up Updates from the first tutorial Journey

Might as well leave a few notes that might help you along the way. If you were doing this Quasar tutorial and had an issue with hot reload not opening, I figured out how to get it working by just running quasar dev again and that seemed to kickstart the hot reload option. I had this happen a few times when i made changes and nothing new showed on the hot reload app.

In order to get highlights working properly in VS Code like teacher’s you should get the extensions for Vue and Sass since they may not be installed. I used:

octref.vetur (Vetur) for Vue because this has html auto-complete as well (another one I tried didn’t…) and

syler.sass-indented for sass stuff

Converting your New App into an Electron App and then Building for Ubuntu with a Debian package

For some reason it doesn’t really say explicitly anywhere in the tutorial above nor on the Quasar site, how to build for Ubuntu / Linux. I assume most developers ‘just know’ this but I didn’t so I had to search and find. For your benefit,

Installing for Ubuntu

Very hard to figure this out for a noob but after a full day of time spent I figured out how to turn this Electron app into an ubuntu native app running in the launcher and everything (exciting moment for a noob, I say!)

I feel like there should be a way to do this right in Quasar with a terminal tag during the build but it seems not.

First, you need to install this by running this on your Quasar dev machine:

npm install -g electron-installer-debian

Then, you build the app with the Quasar electron instructions, but for me it was as simple as running this:

quasar build - m electron

After you run that you’ll find two directories, one of which I still don’t know what it does. The two directories were “my-app-name-linux-x64” and “Unpackaged”

I then created a directory in my quasar project folder at the top level called ‘installers’

I then took the following command which I pulled off the read me page above:

electron-installer-debian --src dist/app-linux-x64/ --dest dist/installers/ --arch amd64

And adjusted the ‘src’ (source) to point to my app-named directory in the electron folder and the ‘dest’ (destination) to the installer directory I created. You can do what you’d like but mine looked like this therefore:

electron-installer-debian --src dist/electron/my-app-name-linux-x64/ --dest installers/ --arch amd64

The result was a fully effective .deb installer file which installed without a hitch and really ended the above tutorial on a high note.

Important note: I had this error:

Creating package (this may take a while)
Error: could not find the Electron app binary at “dist/electron/Quasar App-linux-x64/my-app-name”. You may need to re-bundle the app using Electron Packager’s “executableName” option.

This took a long while to trouble shoot but the issue was nothing more than opening the package.json file and making sure that the following two entries match and probably have dashes in the names (haven’t confirmed that need but it worked with them so I’m sticking to it!)

“name”: “my-app”,
“productName”: “my-app”,

Hope this also saves someone some hair pulling

Cordova Stuff and Ubuntu Touch (raw notes for later)

Cordova is apparently our best hope to get Quasar stuff to be able to convert easily to the Ubuntu Touch framework so I’ll leave my quick notes although they are quick, dirty, and probably fairly useless. I don’t think it can support Electron as per above.

First, apparently… cordova was not installed yet when I ran quasar build -m cordova it never told me that… I had to install cordova with some command that I cannot seem to now find…

Also interesting is that the build let’s you build without error even if you have caps problem in command such as typing ‘Cordova’ instead of ‘cordova’. Neato.

A little late in the game this link was sent to me which I somehow didn’t find before beginning even though I searched. I would have started right here so hopefully this documentation link helps someone save some time.

More to follow, hopefully…

Tags : , , , , ,

How to Load a PDF Floor Plan Into Blender

This is annoyingly hard and I forget how to do it every time so here are some instructions to myself that might also help others.

Convert PDF into PNG Using Gimp

Probably your floor plan is a PDF or you wouldn’t be reading this page, but if it’s a jpg or png kind of file format, then you are done and can skip to the “Importing into Blender” section below.

  1. Make sure you have GIMP installed. Probably you’ll want this since it’s awesome photo manipulation software.
  2. With GIMP open, drag your PDF floor plan page (one page at a time is easier but if it’s one document should work too) and click ‘import’. This will convert the PDF into a working GIMP file.
  3. Adjust the view to an appropriate view orientation since it’s possible when it imported it gets flipped. You may have to adjust the canvas size in the background if you rotate it but that is easy with the ‘fit canvas to layers’ option under ‘image’ menu.
  4. Isolate and select the floor plan with the GIMP selection tools (box select tool is best I find)
  5. Crop out the exact floor plan with the ‘crop to selection’ option under ‘image’ menu.
  6. File, Export
  7. At the bottom left there is a little + plus sign thing that says “Select File Type (by extension)”. Choose this and then scroll through until you find png. Export this file to somewhere you will remember on your device.

Import the Floor Plan Image Into Blender

Most credit to this blog.

In Blender:

  1. Add “Empty” object (shift + A) works
  2. Do steps 1, 2 and 3 in the blog link above of creating an ’empty object’. However, stop there on step 3.
  3. Press number pad 7 to make sure you can see the imported image in orthographic above view. Sometimes you can lose it in the view because it comes in as a plane it’s a plan and pretty razor thin.

That’s it. Now go and turn that floor plan into a 3D amusement park, my friend.

Tags : , ,

Dismissing Firefox popups using Selenium and Python

In my new journey to figure out how to automate stuff in my life, one of the time-sucking adventures was to try to stop browser popups such as geolocation and notifications. I just wanted to click ‘ok’ or ‘dismiss’ and move on since this was my ‘bot’ instance of the browser.

The issue with these browser-based pop ups is that they are handled by the browser, not by selenium so it seems selenium can’t dismiss them or dismiss them easily.

The solution workflow that I found to work well for me is as follows:

  1. Switch to your Selenium Firefox profile
  2. Do your browser setting that you need
  3. Save the change
  4. Start your Selenium script with new changes

Here are the details on how to do this:

Create a new Firefox Profile

  1. in browser, type about:profiles
  2. Create a new profile
  3. Take a note of the location of the root directory of that profile (ie paste to your Selenium script for now)
  4. ‘Launch profile in new browser’ (this will launch your new profile in a new instance nicely)
  5. Make your browser changes and save

Do your browser setting changes

The following two changes were the main two that bothered me so perhaps I’ll highlight those here:

  1. Don’t allow websites to send you notifications
  • Preferences/privacy and security / Notifications
  1. Don’t let websites ask for geolocation stuff
  • Preferences/privacy and security / Permissions – Locations (Settings button)

TIP! It’s very useful to actually do a dry run as a human before you let your bot run free so that you can deal with these popups logged in, one time, as this profile. So, workflow is to switch to your Selenium profile, launch it, do a dry run on with real human clicks, deal with any popups or browser setting stuff, save changes, go run the bot script.

Setting up your Python Script to use your Selenium Profile

Now that you’ve got your new profile, let’s actually use it in your script, instead of what will always be a fresh browser instance

Here is my code block which you can add in your project:

## SETUP SELENIUM TO USE CUSTOM FIREFOX PROFILE

#Pretty sure you need to import this to use 'FirefoxProfile but I'm too lazy to confirm - feel free
from selenium.webdriver.firefox.options import Options 

#Root directory copied from Step 3 above
profilePath = '/home/user/.mozilla/firefox/cjda7321.Selena'

#Directs profile selector thing to the right path created above
profile = webdriver.FirefoxProfile(profilePath) 

#Tells Selenium to use the custom profile
driver = webdriver.Firefox(firefox_profile=profile)

Hope that helps!

Tags : , ,

HOW TO CLICK AN ITEM IN A SUBMENU (UL) LIST USING PYTHON, SELENIUM

I spent literally 3 days trying to simply click a logout link with Selenium. I searched every stackoverflow post I could find until I found this one.

I had tried pretty much everything I could to try to click the logout link which was the fifth item down in the move-over list.

I tried find_element_by_xpath, find_element_by_id, find this, find that, blah blah blah

Finally, it was indeed the find_element_by_css_selector that worked.

The only thing is I still do not know WHY the xpath option didn’t work for this list while the others did. Hmm. Whatever. Probably will figure it out later….HOW TO CLICK AN ITEM IN A SUBMENU (UL) LIST USING PYTHON, SELENIUMThe only thing is I still do not know WHY the xpath option didn’t work for this list while the others did. Hmm. Whatever. Probably will figure it out later….

so, here is a code block of what worked for me to move to a mouse-over menu and click the menu’s submenu item using Selenium and python (my css selector is just a fake example of course so paste your correct one in):

Edit: I also realized I had to click on the button *above* the actual unordered list (UL) element to trigger the drop down. This tip for the ‘main_menu’ element below might also help someone.

main_menu = driver.find_element_by_xpath("//*[@id='with-label']")

actions.move_to_element(main_menu).perform()

time.sleep(2)

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".css-selector-thing > ul:nth-child(2) > li:nth-child(6) > a:nth-child(1)")))

driver.find_element_by_css_selector(".css-selector-thing > ul:nth-child(2) > li:nth-child(6) > a:nth-child(1)").click()
Tags : ,

OPENING A NEW TAB WITH SELENIUM + PYTHON + FIREFOX + UBUNTU

So this was super duper hard and I believe the reason why is because technically the browser settings and the user choices impact whether or not a clicked link opens in a fresh new tab or a fresh new window. Keep that in mind in case you have other headaches. It may be impossible (so I’ve read online) to perfectly control whether a tab opens on your users’ browser, however, since web automation is probably your browser you should be able to work with this solution and your browser settings to get it going.

Another important thing before you begin here. This assumes you are ‘right clicking an element on a page and opening in a new tab’ kind of thing. If you are trying to make a new, unrelated link open in a new tab, this doesn’t work. I’ll figure that out maybe in another blog post. This one takes a page element already in focus and then opens that into a new tab.

Final note: I’m using Ubuntu so not sure if you need to adjust for yourself…

Anyway, here comes the code.

# Import your stuffs
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Set path to your executable Firefox` 
ffpath = '/home/wt/Documents/Waynes_Python_Education_Directory/Automation_Browser_Drivers'

# Turn your Firefox browser into a usable object (or something like that)
driver = webdriver.Firefox(ffpath)

# Come up with a creative new URL to go to (this one is great, btw)
driver.get("https://www.engrish.com/")

# Wait for a while to enjoy it..
time.sleep(5)

# Come up with a creative new URL to go to (this one is great, btw)
new_url = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div[2]/div[1]/div[1]/ul/li[6]/a")

# And now, the magic!  Open fun URL in a new Firefox tab!
new_url.send_keys(Keys.CONTROL + Keys.RETURN)

# Wait for a while to enjoy it..
time.sleep(5)

# Shut 'er down and go home for the day...
driver.quit()
Tags : ,

Overcoming Painful Setup for Selenium with Python on Ubuntu

EDIT 191118
I realized that I need to execute the script below every time my computer reboots so my current workflow is to leave the command commented out in script and then run it before I begin. You can probably run it with the script too? This one: export PATH=$PATH:/home/user/path/to/browser_drivers_for_automation

I had the following continual painfull errors:

  1. selenium.common.exceptions.WebDriverException: Message: ‘my_folder_name’ executable may have wrong permissions.
  2. selenium.common.exceptions.WebDriverException: Message: ‘Automation_Browser_Drivers’ executable needs to be in PATH.

To be transparent, I’m not sure which if any of these steps happened first, or whether it matters, but I’ll give you both in case it helps and in the order I did:

For my setup, since I plan to mess around with automation long term I wanted to have all my different browser drivers in one folder so I can kind of ‘containerize’ them and always know where they are, and update them accordingly. So, I made a directory called ‘browser_drivers_for_automation”

In that, I downloaded all the executables (go figure out how to do that if you want from Selenium page)

The following is the seemingly standard ‘trial run’ to make sure you are setup and working. I definitely recommend not moving forward until you have this trial run going, as well!

from selenium import webdriver

ffpath = '/home/username/path/to/browser_drivers_for_automation'
browser = webdriver.Firefox(ffpath)

browser.get("http://www.python.org")

First, try that. If it runs, awesome, but if you’re like me probably it won’t, HA

So then first, make sure this ‘browser_drivers_for_automation’ directory is listed in your Ubuntu PATH. If you’re like me I didn’t even know what that was but it seems (short version of the story) that this is the part of Ubuntu that says ‘any directory path in here, if you execute a file, I will allow it”

So do this in a terminal:

export PATH=$PATH:/home/user/path/to/browser_drivers_for_automation

not sure what this next one does but I did it so you might as well join me!

source ~/.profile

So now if you do echo $PATH in your terminal you should see your folder listed.

Now, try the above Selenium trial run again. If it works, great. If not, like me, then do this step:

Navigate to your Browser_drivers_for_automation directory and make your driver executable. In my example here i’m using the firefox geckodriver, but you can do this to any/all drivers in here.

sudo chmod +x geckodriver

See if that works. If it does, the browser will open and you should be good to go now.

Hope this helps

Thanks to all those people answering questions in stackoverflow as usual! 🙂

Tags : , ,

How to Do Some Code Changes in Gitlab

I’m not a developer but was encouraged to try a one character change to some software. I felt that I couldn’t break too much so I did my first tiny change. Literally one character text edit. However, it was a bit scary so I’m just posting this to show the basic workflow. This assumes you already have a gitlab account and username and can log in.

1. Find it.

probably you found or someone sent you a link to where the code is and you are on the gitlab page and can see the line of code you’d like to change. If not, get there.

Also, make sure you’re on the right branch. I tried to click ‘edit’ but I was not allowed because I was not on the branch called ‘master’. Your branch that you can edit may have a different name but just be aware that you have to be on the authorized branch that accepts changes. the left side has ‘branches’ and you can look at them there and select the right one.

2. Fork it

When you click ‘edit’ it seems to automatically force you to ‘fork’ the code. This makes sense. You wouldn’t want to disrupt the main code until the overseeing person has reviewed your changes and authorized them. So you ‘fork’ it and do your changes there. I think a fork is basically a copy/paste of the whole block of code for that file

3. Change it.

On the page where you change there is a box where you can comment. I was a bit worried about this but it wasn’t so bad. it’s just a comment box but it seems a bit more important than that. I put my personal comment about the change I made and then saved it.

4. Merge it.

Once you save the changes it becomes a ‘Merge Request’ also known as MR.
I think this part depends on how the project is set up. It might merge automatically into the main software or, it might require a ‘stamp of approval’. Regardless, once you send the MR it’s out of your hands unless you are the developer overseeing the project, also known as the ‘maintainer’.

Hopefully this helps someone else make their first change and thanks to the folks in free software who helped me do this!

Tags : , , ,