.DLL files use C calling conventions, which means that C is more or less related to invoking them, but many programming languages have tools to invoke DLL libraries directly. It's a tad unwieldy, but you can do it. With Java, for instance, you could use the JNA (the Java Native API). Here's a tutorial on how to do it: https://www.techbeamers.com/write-a-simple-jna-program-in-java/
That said, there are easier ways to move the mouse cursor with Java:
import java.awt.Robot; void moveMouse(int x, int y) { new Robot().mouseMove(x, y); }
The problem seems to be that there is a frame on this page (an iframe to be exact). Allow me to use a slightly awkward metaphor:
Imagine Selenium as a tool that scans an item in two dimensions and a simple html page (without frames) as a flat canvas lying on a table. In this situation, Selenium can "see" the whole page at once (like you do). Now imagine you put a cylinder object on top of the canvas. Selenium will keep scanning the canvas level and ignore the top of the cylinder. To scan the top of the cylinder you have to explicitly tell Selenium to change the height at which it scans - but then you can interact only with the top of the cylinder and not the canvas anymore. That's how frames mess things up.
This should allow you to interact with the content of the frame:
frame = driver.find_element_by_class_name('squireIframe') driver.switch_to.frame(frame)
Once you're done doing stuff in the frame, you can use one of the below to get back out to the page proper:
driver.switch_to.parent_frame() # this goes back one level driver.switch_to.default_content() # this goes to root level
There is a ton of resources to Google on this particular Selenium problem, such as this or this.
https://www.techbeamers.com/websites-to-practice-selenium-webdriver-online/
I tend to keep data-driven testing to unit tests or API tests. I would use Selenium for an end to end test, but not every possible scenario. They’re too slow and flaky to be the only testing you do.
I use this syntax for multi-line strings where indenting would harm a triple-quoted string:
def send_email(): message = ("From: From Person <>\n" "To: To Person <>\n" "Subject: SMTP e-mail test\n" "\n" "This is a test e-mail message." ) return message
mesg = send_email() print(type(mesg), len(mesg)) print(mesg)
which produces this output:
<class 'str'> 129 From: From Person <> To: To Person <> Subject: SMTP e-mail test
This is a test e-mail message.
See the section titled "Use brackets to define a multiline string" here:
Part of it is legacy from other languages, where try/except is for catching errors. In Python you see it used a lot more for cases of flow control, and it's fairly common, but that doesn't mean it should replace the if statement.
You should still be using it to trap the exceptions, not the expected. And where possible you should always specify the exception you're catching so that you don't accidentally eat an exception that is expected to be caught somewhere else. Perhaps you have a handler for a timeout, or a threading issue, but your open ended exception for converting an int catches it instead. Not great!
This article is pro-using try-except, in the right circumstances:
I'm actually working on the same thing. And found this: https://www.techbeamers.com/iterate-strings-python/
Which suggests this syntax:
for char in string_to_iterate[ : : -1]: print(char)
Haven't tried it yet but that's what I plan when I get back to the computer.
The input()
function (which can include a prompt message, so the user knows what the programme is waiting for) ALWAYS returns a string, even if you enter only numerical digits. You need to convert the input to an integer:
year_of_birth = int( input('What year were you born? ')) current_year = int( input('What year are we in? '))
You can of course find out the date without asking the user:
from datetime import date today = date.today() print("Today's date:", today)
You can do simple arithmetic between your two integer inputs. Of course, this doesn't take account of the month of birth!
You can also extract the details you need using the date functions imported as described above and do the calculation you require.
Maybe try finding the element by xpath? Something like:
.findElement(By.xpath("//option[0]"))
, possibly adding .text
on the end? (just pulled this from google, here to be specific.)
Try send_keys(Keys.CONTROL,Keys.SHIFT,'M')
I suspect the reason that ctrl+t doesn't appear to work is because Selenium does not automatically switch its focus to a new tab; you have to use switch_to_window() to explicitly switch focus to the new tab.
Usually this happens if you try to delete a folder which is not empty instead a FILE. Let me show you how I delete stuff using Python :)
​
​
1) os.unlink('your path')
- Delete the file at the path you pass in. This is same as os.remove('your path')
eg: os.unlink('C:\\users\\tpBlacks\\desktop\\new.txt')
​
2) os.rmdir('your path')
- Delete the folder at the path you pass in. This folder must be empty.
eg: os.rmdir('C:\\users\\tpBlacks\\desktop\\myBlankFodler')
​
3) shutil.rmtree('your path')
- Delete the folder at the path you pass in. It doesn't matter whether folder is empty or not.
eg: shutil.rmtree('C:\\users\\tpBlacks\\desktop\\mySpreadsheets')
​
​
make sure to import os for the first two methods and shutil for the third method before using otherwise you'll end up with an Error.
Finally take a look at shutil module here. It has a pretty good usage - https://www.techbeamers.com/python-shutil-module/
​
Hope this helps !
Nice list there in your post, though, there could be many more good questions you might like to add such as:
If you wish, then refer from here - python interview questions
Hello fren.
I can recommend this one https://www.techbeamers.com/selenium-webdriver-tutorial/
They have really good explanation and a lot of examples how to write tests (Java and Python too).