how solve x12 is already defined context: var >>> x12 <<< >= 0; - ampl

enter image description here I don't understand to solve it, my lecturer gives the task but he teach nothing about it and don't give any references.
enter image description here I can get the same result like that. Thank you so much.

Related

asking for Selenium *find_element_by_class_name

I have tried to get the text from the helpful and unhelpful button but I couldn't succeed:
for example: I want to get "6013" for helpful points and "320" for unhelpful points:
my code is:
product_helpful.append(container.find_element_by_class_name('css-0').text)
product_not_helpful.append(container.find_element_by_class_name('css-0').text)
you can check the picture for your reference:
enter image description here
Use the title attribute to target the helpful vs unhelpful portion of the code
product_helpful.append(container.find_element_by_css_selector('[title="Helpful"] span').text)
product_not_helpful.append(container.find_element_by_css_selector('[title="Unhelpful"] span').text)
Note that for this you must use the find_element_by_css_selector method from the WebElement.

Finding color of the text in selenium

Below is the code, trying to find the colour of the text 'Special Assistance' in spicejet.com. I am expecting rgb value as (196,18,48) (as shown in the developer view during inspection of the element)
however when i run the program it displays value as rgba (0,0,0,1);
driver.get("https://www.spicejet.com");
driver.manage().window().maximize();
WebElement ele = driver.findElement(By.xpath("//a[text()='Special Assistance']"));
System.out.println(ele.getCssValue("color"));
please help
That page looks like it has multiple elements that match that xpath. As such I think you're getting the wrong one returned and the color is actually correct.
If you're actually looking for the red special assistance link this might be a better (more specific) xpath:
//*[#id='discount-checkbox']//a[text()='Special Assistance']
Try that, and I think you may find the expected results.

.click function for selenium works inconsistently - chrome

I have this simple code to click the first paper link Organoid Modeling of the Tumor Immune Microenvironment. at this link.
title_wait = WebDriverWait(driver,5).until(
EC.presence_of_element_located((By.CLASS_NAME, "docsum-title")))
print('found title '+str(title))
element = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.LINK_TEXT, str(title)))).click();
print('found link to click')
My code will sometimes work, but around 50% of the time it just skips right over the .click() and goes to the print below. Any help would be appreciated!
Actually, the problem is not with the wait time. U have made a small mistake in this line: element = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.LINK_TEXT, str(title)))).click();
First of all, title is a variable of type selenium.webdriver.remote.webelement.WebElement. When u convert this into a str, u get this: <selenium.webdriver.remote.webelement.WebElement (session="21a8944e81b4dce8386fdf91067a2ddd", element="17660b77-61f4-4b2d-b5e8-f845ce97ad1e")>. So this is not the right way to get the text.
The right way is to use .text. Replace str(title) with title.text. Ur code should work. Here is the final code:
title = WebDriverWait(driver,5).until(
EC.presence_of_element_located((By.CLASS_NAME, "docsum-title")))
print('found title '+ title.text)
element = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.LINK_TEXT , title.text))).click();
print('found link to click')
As Arundeep pointed out, u can increase the wait time to make ur code better. But this was the main problem in ur code.

I am working with code but is does not provide me desire result. Can you please tell me how to Scrape Facebook comments text from fb live or post?

I want to scrape facebook comments from fb live or post,..is there any way to get this? If anyone know please help me.
I am using this but it does not working.
Code:
comments = driver.find_elements_by_css_selector('.UFICommentBody span')
print("Comment found " +str(len(comments)))
for x in range(len(comments)):
print (comments[x])
Output:
<selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="a0a4c59f-9c84-4a5c-855d-3ba51cea249a")>
<selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="504c6ef2-e9fe-42b7-9f68-dcee5e7dbfde")>
<selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="06d25f07-3a20-4783-98d7-f9c0ae01c230")>
<selenium.webdriver.remote.webelement.WebElement (session="0ea2c4e211c05d504536a1bef2259260", element="5e6b1e94-fee8-4636-9d9e-fd992c945c19")>
if you want to print text from your list then you can use for loop to retrieve each element through your list and then use .text with each object to print assoociated text.
print("Comment found " +str(len(comments)))
for x in range(len(comments)):
print (comments[x].text)
or
print("Comment found " +str(len(comments)))
for x in range(len(comments)):
print (x.text)
To get the text from the elements, you need to do this (assuming you are using python):
print (comments[x].text)

security issue with MSCAPTCHA

I'm using MSCAPTCHA in one of my projects .
Now I Know that Captchas that their characters are dependent to their image url could be passed by hackers easily .
I mean if we copy the captcha image url and open it in new browser window and refresh it the same characters would be generated .
and hackers have ways to use this bug . How ? they write a small program that request our page except the captcha then they use that first captcha image url . and they pass the captcha . ( I've read this somewhere and I don't know details too )
Now any idea how to solve this ? or is there any captcha without this problem ?
I don't know MSCAPTCHA in particular, but you seem to have a misunderstanding of how captchas are solved. Yes, each captcha image has a unique URL. That's fine and irrelevant. The form that the captcha belongs to has some sort of information that requires the user to solve a specific captcha. A user cannot simply answer any random captcha he wants.
While preparing the form that is presented to the user, the server generates a captcha and saves the expected answer internally, in the user's session for instance. It then sends the link to the specific captcha image to the user with the form. If the returned answer is not what is expected, the solution is rejected. It doesn't matter if the user tries to look at some other captcha than the one sent by the server.
Perhaps something to sidestep the problem while still addressing underlying requirement of human vs robot verification that captcha fills?
I implemented something of my own which a human reader should be able to read. I'd ask them
"I have AA stones and I gather BB more. I now have [textbox_here] stones overall".
The pseudo code is like:
Random rand = new Random();
int intNums[] = {0,1,2,3,4,5,6,7,8,9};
string strNums[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int aIndex = rand.Next(0,4); // 0, inclusive, 5 exclusive
int bIndex = rand.Next(0,4);
// 1. use AA and BB below to print your HTML form
string AA = strNum[aIndex];
string BB = strNum[bIndex];
// 2. save/pass out "rightAnswer" to later verify
// the users answer from the textbox
int rightAnswer = aIndex + bIndex;
I prefer this since it's lightweight, no external dependencies and so far it's worked (no spam). You can also try an array of question and answers like
string questionArray[] = { "My mother has only one son. Am I male or female?", ... };
string answerArray[] = { "male", ... };
You get the idea ...
Hope it helps!