A variable is cannot be found in scope - scope

Friends,
Could you please explain to me why when I use string:
destinationVC.bmiValue = String (format: "% .1f", bmi)
Pops up error that bmi is cannot be found in scope? Swift just says it can't find bmi variable in the CalculateViewController class.
enter image description here
But when I set the new bmiValue variable, the program works fine.
enter image description here
How it comes?
Thanks in advance.

I found that:
It's not allowed to jump from function to function directly, it appropriate needs to set var or let above list, after class line.
I hope this information would be useful for new others.

Related

How to retrieve text by xpath

Hey everyone
I am 15 years old and I'm currently making a python/selenium script that automatically loges in on my school page and goes in to see what homework i have tomorrow.
The way I want it to check if we have received homework is if the text box which is: "LB MAT 86" is something else (because that means we have received homework)
Let me now tell you about my problem:
Picture: https://i.stack.imgur.com/WLjuR.png
But first, let me tell u how my "homework page" is designed and works.
On the picture you see that I have inspected the text: "LB MAT 86".
LB is the abbreviation of my teachers name.
MAT stands for "matematik" with just means math in english.
86 is the class number our class have.
When we get homework our teacher deletes the text "LB MAT 86" and instead writes the homework we get.
My question for you is how can I find the text. The only way I can see how you can find the text is by its location.
The xpath of the text field: //*[#id="sk-diary-notes-container"]/div/div[1]/div/table/tbody/tr[3]/td[3]/text()[1]
The full xpath of the text field: /html/body/div[1]/div[2]/div[3]/div[2]/div/div/div[1]/div/table/tbody/tr[3]/td[3]/text()[1]
OuterHTML:   LB MAT 86
Thanks
driver.find_element_by_xpath("//table[contains(#align,'center')//td[contains(.,'LB MAT 86')]")
Would get the element with text LB MAT 86.
You can add some code to find the current index to check for your code. /tr[i]/td[i]
Try using this xpath
locator = driver.find_element_by_xpath("//table[contains(#align,'center')/tbody/tr[3]/td[3]")
You should get everything including nbsp (non-braking space).
Then split the result and get everything after nbsp;
You did not include html code, only screenshot. Next time include it (or include it now).
After you test the correct locator, try to use split(). It will get the last element from your text divided by space. I am not 100% sure it will work, experiment by yourself.
mystring = locator.text
desired_text = result = mystring.split(' ')[-1]

Python: why can a variable stand on its own?

I am a beginner in python told my friend today, that the following code would throw an error, but it did not:
a = 5
a
So I wondered, what does "a" actually do and why is the interpreter fine with this?
If this is a duplicate, please refer me to the right post and sorry in advance.
edit: I used a *.py file.
If you type this code into the shell and click enter, the value of a is returned. Functionally, as there is no operation being performed on a, the value of a will not change.
You define the variable in the line above. The variable contains a value, so the "NameError: name 'a' is not defined" error is not triggered.
Also, even if the variable is a different data type, for example, a string, the value of a is returned.
If you run the code in a different environment, the line won't be printed and the line won't impact the value of itself or of any other variables.
I think you tried it in der REPL Console, paste it to a *.py file and execute that. So when you just type the variable name and hit enter this is actually a print command behind the scenes
You can type in a int into the shell or whatever, and it will return it. The variable you put is just a int, so it returns 5.

Selenium Python Issue

browser.find_element_by_xpath('//div[contains(text(), "SomeData")]')
I want to pass a variable instead of a string, I am using Selenuim with python. In this Case A div will be found with text of "SomeData" everytime instead of passing a value as string I want it a variable, which will change everytime I run the code.
I cannot give a correct answer as I am unable to fully understand your question. But lets assume, you want to have some part of your stated xpath as a variable, that part can be stored in a variable and then referenced in your function call.
And my_variable can be controlled in your code and change value as needed without writing complete xpath
Again having said that, more clarity on your question will help the community help you bette
my_variable = 'SomeData'
browser.find_element_by_xpath(f'//div[contains(text(), "{my_variable}")]')
if you are using python version less that 3.6
my_variable = 'SomeData'
browser.find_element_by_xpath(f'//div[contains(text(), "{my_variable}")]'.format(my_variable=my_variable))
or syntax provided in the comment by Andersson

findElement By XPath not supported in Selenium VBA?

variableName = driver.findElement(By.XPath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]"))
Running the above always seems to lead to the error:
Why is this? I always see other people using findElement By XPath. If it helps, I generated about half of my code using Selenium's 'record' feature. I then converted the code into 'VBA/Webdriver' before pasting it into Excel to use as a Macro.
What exactly is wrong with my code? I have used findElement a number of times before, so I'd have to guess that the problem is with the By.XPath part of my code... Is there any way around this?
Edit: Even variableName = driver.findElementsByXPath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]") leads to the error 'Invalid procedure call or argument' even though it looks fine to me.
Try:
variableName = driver.findElementByXPath("//div[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]")
Notice that I removed the . in the beginning of the xPath and replaced * with div. Also, you're missing something at the end. You are just declaring the path here and not really getting a value.
EDIT: Referring to just the xPath is not usually enough. Do you want to perform an action on it, get the text inside, the tagname, etc.?
EDIT2: Testing to get the .Text attribute returns a "findElement By XPath not supported in Selenium VBA?" message.
Here's what works for me:
Dim variableName() as variant
variableName = driver.findElementsByXPath("//div[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]").getdata
Notice it's "find elements [plural] by XPath". This creates a two-dimensional array. variableName(1,1) will have the data you're looking for.
(I know it's been more than 6 years, but it's my first contribution and I can't resist! Maybe that can help someone else)
You have to initialise the following:
Dim By As New By, variableName As WebElement
and because variableName is an object, it has to be declared, as follows:
Set variableName = driver.FindElement(By.Xpath(".//*[#id='T_F2']/fieldset/div[1]/div/div[4]/span[2]"))

VB6 Read String From Resource

I have text file in VB6 Application resources, and I am trying to read the text in it.
How to do that? I have been searching for hours without a proper solution. Somebody please help me.
My code is:
Private Sub Command1_Click()
Dim URL As String
URL = LoadResString(101)
MsgBox URL
End Sub
This maybe explains it more: http://i.imgur.com/wGnWCBb.jpg
Is this even possible? Somebody please spoonfeed me, I would appreciate that a lot.
I am trying to read the string from resource to a variable(string) and then prompt it with messagebox.
Some simple solution would be great. Also, if this is possible with FindResource API, please tell me how or point me to the right direction.
I had to do something like this many years ago.
I used s = StrConv(LoadResData(resId, resType), vbUnicode). The resource was an ANSI (non-unicode) file.
resType was a custom type I just made up when I saved the resource.
I had an issue with a double null that got appended at the end of the text, and which had to be removed. I can't remember the exact reason why that happens, but I presume it has to do with the resource being stored as a double-null-terminated list of C-strings.
If I had to guess, you'll have better luck with LoadResData(). Make sure to use both parameters (the id and type ones).

Resources